diff --git a/conformance/org.universaal.tools.conformanceTools/src/org/universaal/tools/conformanceTools/Activator.java b/conformance/org.universaal.tools.conformanceTools/src/org/universaal/tools/conformanceTools/Activator.java index 35c964f1e427b2553d034f64d35d1dda97573a87..a7fe1679529051c2e6ee3e76063a6c001aab1557 100644 --- a/conformance/org.universaal.tools.conformanceTools/src/org/universaal/tools/conformanceTools/Activator.java +++ b/conformance/org.universaal.tools.conformanceTools/src/org/universaal/tools/conformanceTools/Activator.java @@ -32,9 +32,9 @@ public class Activator extends AbstractUIPlugin { bundleContext = context; plugin = this; if(context.getBundle().getLocation().startsWith("initial")) - absolutePath = context.getBundle().getLocation().replace("initial@reference:file:/", ""); + absolutePath = context.getBundle().getLocation().replace("initial@reference:file:", ""); else - absolutePath = context.getBundle().getLocation().replace("reference:file:/", ""); + absolutePath = context.getBundle().getLocation().replace("reference:file:", ""); } /* diff --git a/conformance/org.universaal.tools.conformanceTools/src/org/universaal/tools/conformanceTools/run/AALDirectivesMavenPlugin.java b/conformance/org.universaal.tools.conformanceTools/src/org/universaal/tools/conformanceTools/run/AALDirectivesMavenPlugin.java new file mode 100644 index 0000000000000000000000000000000000000000..3598aaee9836ce8221db2e3e617f16eb59bb3201 --- /dev/null +++ b/conformance/org.universaal.tools.conformanceTools/src/org/universaal/tools/conformanceTools/run/AALDirectivesMavenPlugin.java @@ -0,0 +1,204 @@ +package org.universaal.tools.conformanceTools.run; + +import java.io.File; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Properties; + +import org.apache.maven.execution.MavenExecutionRequest; +import org.apache.maven.execution.MavenExecutionResult; +import org.apache.maven.model.Dependency; +import org.apache.maven.model.Model; +import org.apache.maven.model.Plugin; +import org.apache.maven.model.PluginExecution; +import org.apache.maven.model.ReportPlugin; +import org.apache.maven.model.Reporting; +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IWorkspace; +import org.eclipse.core.resources.IWorkspaceDescription; +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.m2e.core.MavenPlugin; +import org.eclipse.m2e.core.embedder.IMaven; +import org.eclipse.m2e.core.internal.IMavenConstants; +import org.eclipse.m2e.core.project.IMavenProjectFacade; +import org.eclipse.m2e.core.project.IMavenProjectRegistry; +import org.universaal.tools.conformanceTools.utils.POMeditor; + +public class AALDirectivesMavenPlugin { + + private IProject p; + private File pom; + private POMeditor pomEditor; + + private final String UAAL_GID = "org.universAAL"; + private final String UAAL_AID = "uAAL.pom"; + + private final String UAAL_PLUGIN_GROUP_ID = "org.universAAL.support"; + private final String UAAL_PLUGIN_ARTIFACT_ID = "uaalDirectives-maven-plugin"; + private final String UAAL_PLUGIN_VERSION = "1.3.1-SNAPSHOT"; + + // it seems to be not working without adding this dependency + private final String DOXIA_PLUGIN_GROUP_ID = "org.apache.maven.doxia"; + private final String DOXIA_PLUGIN_ARTIFACT_ID = "doxia-sink-api"; + private final String DOXIA_PLUGIN_VERSION = "1.3"; + + public AALDirectivesMavenPlugin(IProject project){ + this.p = project; + this.pom = new File(project.getFile("pom.xml").getLocation()+""); + + pomEditor = new POMeditor(this.pom); + } + + public List<Throwable> executeTests(){ + + List<Throwable> output = null; + + try{ + if(verifyAALDMPinPOMfile()){ + output = runTest(); + if(output != null) + for(int i = 0; i < output.size(); i++) + System.out.println("**\ngetLocalizedMessage: "+output.get(i).getLocalizedMessage()+ + " \ngetMessage: "+output.get(i).getMessage()+ + " \ngetCause: "+output.get(i).getCause()); + } + } + catch(Exception ex){ + ex.printStackTrace(); + } + + return output; + } + + private boolean verifyAALDMPinPOMfile(){ + + try{ + boolean plugin_bool = false, dependency_bool = false, reporting = false; + + Model pomC = pomEditor.getPomContent(); + if(pomC.getParent() != null){ + if(!pomC.getParent().getGroupId().equalsIgnoreCase(UAAL_GID) || + !pomC.getParent().getArtifactId().equalsIgnoreCase(UAAL_AID)) + System.out.println("[WARNING] Selected project has a different PARENT declaration in POM file than "+UAAL_GID+"/"+UAAL_AID); + } + else{ + System.out.println("[WARNING] Selected project has not PARENT declaration in POM file equal to "+UAAL_GID+"/"+UAAL_AID); + } + if(pomC.getBuild() != null){ + if(pomC.getBuild().getPlugins() != null){ + for(int i = 0; i < pomC.getBuild().getPlugins().size(); i++){ + if(pomC.getBuild().getPlugins().get(i).getArtifactId().equalsIgnoreCase(UAAL_PLUGIN_ARTIFACT_ID)){ + + plugin_bool = true; + + if(pomC.getBuild().getPlugins().get(i).getDependencies() != null){ + for(int j = 0; j < pomC.getBuild().getPlugins().get(i).getDependencies().size(); j++){ + if(pomC.getBuild().getPlugins().get(i).getDependencies().get(j).getArtifactId().equalsIgnoreCase(DOXIA_PLUGIN_ARTIFACT_ID)){ + + dependency_bool = true; + } + } + } + } + } + } + if(pomC.getReporting() != null){ + for(int i = 0; i < pomC.getReporting().getPlugins().size(); i++){ + if(pomC.getReporting().getPlugins().get(i).getArtifactId().equalsIgnoreCase(UAAL_PLUGIN_ARTIFACT_ID)) + reporting = true; + } + } + } + + if(!plugin_bool){ + + Plugin pl = new Plugin(); + pl.setArtifactId(UAAL_PLUGIN_ARTIFACT_ID); + pl.setGroupId(UAAL_PLUGIN_GROUP_ID); + pl.setVersion(UAAL_PLUGIN_VERSION); + pomC.getBuild().getPlugins().add(pl); + + } + if(!dependency_bool){ + // doxia-sink-api dependency not found + Dependency d = new Dependency(); + d.setArtifactId(DOXIA_PLUGIN_ARTIFACT_ID); + d.setGroupId(DOXIA_PLUGIN_GROUP_ID); + d.setVersion(DOXIA_PLUGIN_VERSION); + for(int i = 0; i < pomC.getBuild().getPlugins().size(); i++){ + if(pomC.getBuild().getPlugins().get(i).getArtifactId().equalsIgnoreCase(UAAL_PLUGIN_ARTIFACT_ID)){ + pomC.getBuild().getPlugins().get(i).addDependency(d); + System.out.println(DOXIA_PLUGIN_ARTIFACT_ID+" dependency added!"); + } + } + } + if(!reporting){ + ReportPlugin rp = new ReportPlugin(); + rp.setArtifactId(UAAL_PLUGIN_ARTIFACT_ID); + rp.setGroupId(UAAL_PLUGIN_GROUP_ID); + rp.setVersion(UAAL_PLUGIN_VERSION); + pomC.setReporting(new Reporting()); + pomC.getReporting().addPlugin(rp); + } + + for(int i = 0; i < pomC.getBuild().getPlugins().size(); i++) + if(pomC.getBuild().getPlugins().get(i).getArtifactId().equalsIgnoreCase(UAAL_PLUGIN_ARTIFACT_ID)){ + PluginExecution pex = new PluginExecution(); + pex.addGoal("check"); + pex.setId("CT tool"); + pex.setPhase("verify"); + pex.setInherited(false); + pomC.getBuild().getPlugins().get(i).addExecution(pex); + + return true; + } + } + catch(Exception ex){ + ex.printStackTrace(); + } + + return false; + } + + private List<Throwable> runTest(){ + + try{ + IMavenProjectRegistry projectManager = MavenPlugin.getMavenProjectRegistry(); + IFile pomResource = p.getFile(IMavenConstants.POM_FILE_NAME); + IMavenProjectFacade projectFacade = projectManager.create(pomResource, true, null); + + IMaven maven = MavenPlugin.getMaven(); + if(pomResource != null && projectFacade != null){ + MavenExecutionRequest request = projectManager.createExecutionRequest(pomResource, projectFacade.getResolverConfiguration(), null); + + List<String> goals = new ArrayList<String>(); + Properties props = new Properties(); + + IWorkspace workspace = ResourcesPlugin.getWorkspace(); + IWorkspaceDescription description = workspace.getDescription(); + if (!description.isAutoBuilding()) + goals.add("compiler:compile"); // compile it if autobuilding is off + + //goals.add("install"); + goals.add("verify"); + + request.setGoals(goals); + request.setUserProperties(props); + MavenExecutionResult execution_result = maven.execute(request, null); + if(execution_result.getExceptions() == null || execution_result.getExceptions().isEmpty()){ + return Arrays.asList(new Throwable("No errors have been found!")); + } + else{ + return execution_result.getExceptions(); + } + } + } + catch(Exception ex){ + ex.printStackTrace(); + } + + return Arrays.asList(new Throwable("Something went wrong!")); + } +} \ No newline at end of file diff --git a/conformance/org.universaal.tools.conformanceTools/src/org/universaal/tools/conformanceTools/run/ToolsRun.java b/conformance/org.universaal.tools.conformanceTools/src/org/universaal/tools/conformanceTools/run/ToolsRun.java index 2bde28cf1ad7745bbbaf9be01a9ffe7f7e77456b..7c1a122706fd2ee45ed70b27f2adbf632038ad85 100644 --- a/conformance/org.universaal.tools.conformanceTools/src/org/universaal/tools/conformanceTools/run/ToolsRun.java +++ b/conformance/org.universaal.tools.conformanceTools/src/org/universaal/tools/conformanceTools/run/ToolsRun.java @@ -49,6 +49,7 @@ import org.universaal.tools.conformanceTools.checks.impl.Maven_nature; import org.universaal.tools.conformanceTools.checks.impl.NameGroupID; import org.universaal.tools.conformanceTools.checks.impl.OSGI_bundle; import org.universaal.tools.conformanceTools.checks.impl.POM_file; +import org.universaal.tools.conformanceTools.checks.impl.UICallerImpl; import org.universaal.tools.conformanceTools.markers.CTMarker; import org.universaal.tools.conformanceTools.markers.Markers; import org.universaal.tools.conformanceTools.utils.HtmlPage; @@ -99,12 +100,12 @@ public class ToolsRun { this.window = window; this.selection = window.getSelectionService().getSelection("org.eclipse.jdt.ui.PackageExplorer"); - if(this.selection == null){ + if(this.selection == null)//{ this.selection = window.getSelectionService().getSelection("org.eclipse.ui.navigator.ProjectExplorer"); - System.out.println("uAAL CT - using selection from Project Explorer."); - } - else - System.out.println("uAAL CT - using selection from Package Explorer."); + // System.out.println("uAAL CT - using selection from Project Explorer."); + // } + // else + // System.out.println("uAAL CT - using selection from Package Explorer."); if ((selection != null) && (selection instanceof StructuredSelection)) { @@ -130,16 +131,20 @@ public class ToolsRun { if(plugin == RunPlugin.CustomChecks){ + // AALDirectivesMavenPlugin tests = new AALDirectivesMavenPlugin(this.projectToAnalyze); + // List<Throwable> results = tests.executeTests(); + List<String> checks = new ArrayList<String>(); checks.add(ActivatorCheck.class.getName()); checks.add(Maven_nature.class.getName()); checks.add(NameGroupID.class.getName()); checks.add(OSGI_bundle.class.getName()); checks.add(POM_file.class.getName()); - //checks.add(UICallerImpl.class.getName()); + // TODO checks.add(UICallerImpl.class.getName()); List<Result> results = test(checks); visualizeResultsCC(results); + //visualizeResultsAALDirectives(results); } } catch(Exception ex){ ex.printStackTrace(); } @@ -190,10 +195,7 @@ public class ToolsRun { } } - if(results != null) - return results; - - return null; + return results; } private void testConformance() throws CoreException { @@ -494,14 +496,12 @@ public class ToolsRun { int k = 0; for(int i = 0; i < orderderbugsMap.size(); i++){ if(orderderbugsMap.get(i) != null) - //if(orderderbugsMap.get(i).getPlugin() == this.plugin){ orderderbugsMap.set(i, null); k++; - //} } - System.out.println("uAAL CT - deleted "+k+" bug instances."); + //System.out.println("uAAL CT - deleted "+k+" bug instances."); - markers.deleteAll(/*this.plugin*/); + markers.deleteAll(); } catch(Exception ex){ ex.printStackTrace(); @@ -674,6 +674,50 @@ public class ToolsRun { } } + private void visualizeResultsAALDirectives(List<Throwable> results){ + + try{ + HtmlPage page = new HtmlPage("uAAL CONFORMANCE TOOLS - Test results from AAL Directives Maven Plugin"); + //String path_ = ResourcesPlugin.getWorkspace().getRoot().getLocation().makeAbsolute()+"/"+projectToAnalyze.getDescription().getName()+"/target/site/images/logos/"; + + Table t = page.new Table(results.size()+2, 4); + + // table header + t.addContentCentered("<font size='5'><b>TEST RESULT</b></font>", 0, 0); + //t.addContentCentered("<font size='5'><b>TEST NAME</b></font>", 0, 1); + t.addContentCentered("<font size='5'><b>TEST DETAILS</b></font>", 0, 2); + //t.addContentCentered("<font size='5'><b>RESULT DESCRIPTION</b></font>", 0, 3); + + for(int i = 0; i < results.size(); i++){ + Throwable check = results.get(i); + // t.addContentCentered("<img src='"+path_+check.getResultImg()+"' />", i+1, 0); + // t.addContentCentered(check.getCheckName(), i+1, 1); + // t.addContentCentered(check.getCheckDescription(), i+1, 2); + // t.addContentCentered(check.getResultDscr(), i+1, 3); + t.addContentCentered(check.getLocalizedMessage(), i+1, 0); + //t.addContentCentered(check.getCause().getMessage(), i+1, 1); + if(check.getStackTrace() != null) + t.addContentCentered(check.getStackTrace().toString(), i+1, 2); + else + t.addContentCentered("No details.", i+1, 2); + // check.getCause(); + // check.getLocalizedMessage(); + // check.getStackTrace(); + } + + page.getBody().addElement(t.getTable()); + page.getBody().addElement("<br/><br/><p>Total: 9/*"+results.size()+"*/ performed test(s).</p>"); + String filePath = ResourcesPlugin.getWorkspace().getRoot().getLocation().makeAbsolute()+"/"+projectToAnalyze.getDescription().getName()+"/target/site/"+fileNameResults; + File file = new File(filePath); + page.write(file); + + IDE.openEditorOnFileStore( window.getActivePage(), EFS.getLocalFileSystem().getStore(file.toURI()) ); + } + catch(Exception ex){ + ex.printStackTrace(); + } + } + private void visualizeResultsFC(List<BugDescriptor> bugs){ try{ @@ -728,7 +772,7 @@ public class ToolsRun { Bundle bundle = Platform.getBundle(Activator.PLUGIN_ID); File sourceDir; - File[] icons; + File[] icons = new File[0]; if(!Activator.absolutePath.endsWith("jar")){ sourceDir = new File(Activator.absolutePath+"/icons/"); @@ -767,10 +811,11 @@ public class ToolsRun { if(!logos.exists()) logos.mkdir(); - for(File icon: icons){ - Utilities.copyFile(bundle, destAbsPath+destInternalProjectPath, icon.getName(), "/icons/"); - Utilities.copyFile(bundle, destAbsPath+destInternalProjectPath+"logos/", icon.getName(), "/icons/"); - } + if(icons != null && icons.length > 0) + for(File icon: icons){ + Utilities.copyFile(bundle, destAbsPath+destInternalProjectPath, icon.getName(), "/icons/"); + Utilities.copyFile(bundle, destAbsPath+destInternalProjectPath+"logos/", icon.getName(), "/icons/"); + } } catch(Exception ex){ ex.printStackTrace(); diff --git a/conformance/org.universaal.tools.conformanceTools/src/org/universaal/tools/conformanceTools/utils/POMeditor.java b/conformance/org.universaal.tools.conformanceTools/src/org/universaal/tools/conformanceTools/utils/POMeditor.java new file mode 100644 index 0000000000000000000000000000000000000000..cdaabfaa0bfedcd4460d2591cebe1fe0ea95dfe0 --- /dev/null +++ b/conformance/org.universaal.tools.conformanceTools/src/org/universaal/tools/conformanceTools/utils/POMeditor.java @@ -0,0 +1,126 @@ +package org.universaal.tools.conformanceTools.utils; + +import java.io.File; +import java.io.FileReader; +import java.io.Reader; + +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.transform.Transformer; +import javax.xml.transform.TransformerFactory; +import javax.xml.transform.dom.DOMSource; +import javax.xml.transform.stream.StreamResult; + +import org.apache.maven.model.Model; +import org.apache.maven.model.io.xpp3.MavenXpp3Reader; +import org.w3c.dom.Document; + +public class POMeditor { + + private File pom; + public Document parsedPom; + + public POMeditor(File pom){ + this.pom = pom; + } + + public Model getPomContent(){ + + try{ + Model model; + Reader reader = new FileReader(pom); + MavenXpp3Reader xpp3Reader = new MavenXpp3Reader(); + model = xpp3Reader.read(reader); + reader.close(); + + DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance(); + DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder(); + Document parsedPom = docBuilder.parse(pom); + parsedPom.getDocumentElement().normalize(); + + this.parsedPom = parsedPom; + + return model; + } + catch(Exception ex){ + ex.printStackTrace(); + } + + return null; + } + + // public INSERT_OUTPUT insertNode(Element father, Element child){ + // + // try{ + // DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance(); + // DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder(); + // Document parsedPom = docBuilder.parse(pom); + // parsedPom.getDocumentElement().normalize(); + // + // // NodeList fathers = parsedPom.getElementsByTagName(father.getNodeName()); + // // if(fathers.getLength() == 0) + // // return INSERT_OUTPUT.FATHER_NOT_FOUND; + // // else if(fathers.getLength() > 1) + // // return INSERT_OUTPUT.TOO_MANY_FATHERS; + // // else{ + // // // ok + // + // for(int i = 0; i < parsedPom.getDocumentElement().getChildNodes().getLength(); i++){ + // if(parsedPom.getDocumentElement().getChildNodes().item(i).isEqualNode(father)){ + // parsedPom.getDocumentElement().getChildNodes().item(i).appendChild(child); + // break; + // } + // } + // + // // write the content into xml file + // TransformerFactory transformerFactory = TransformerFactory.newInstance(); + // Transformer transformer = transformerFactory.newTransformer(); + // DOMSource source = new DOMSource(parsedPom); + // StreamResult result = new StreamResult(pom); + // transformer.transform(source, result); + // + // return INSERT_OUTPUT.SUCCESS; + // //} + // } + // catch(Exception ex){ + // ex.printStackTrace(); + // } + // + // return INSERT_OUTPUT.FAILED; + // } + + public INSERT_OUTPUT insertNode(String nodeName){ + + try{ + DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance(); + DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder(); + Document parsedPom = docBuilder.parse(pom); + parsedPom.getDocumentElement().normalize(); + + parsedPom.createElement(nodeName); + + // write the content into xml file + TransformerFactory transformerFactory = TransformerFactory.newInstance(); + Transformer transformer = transformerFactory.newTransformer(); + DOMSource source = new DOMSource(parsedPom); + StreamResult result = new StreamResult(pom); + transformer.transform(source, result); + + return INSERT_OUTPUT.SUCCESS; + } + catch(Exception ex){ + ex.printStackTrace(); + } + + return INSERT_OUTPUT.FAILED; + } + + public Document getParsedPom() { + return parsedPom; + } + + public enum INSERT_OUTPUT{ + + SUCCESS, FAILED, FATHER_NOT_FOUND, TOO_MANY_FATHERS + } +} \ No newline at end of file diff --git a/conformance/org.universaal.tools.conformanceTools/src/org/universaal/tools/conformanceTools/utils/RunPlugin.java b/conformance/org.universaal.tools.conformanceTools/src/org/universaal/tools/conformanceTools/utils/RunPlugin.java index 932ee034ecf084a27809e564b971dc0c5dbe3100..a196497792dd6cea37ac8e770c6b1d60f9388f3f 100644 --- a/conformance/org.universaal.tools.conformanceTools/src/org/universaal/tools/conformanceTools/utils/RunPlugin.java +++ b/conformance/org.universaal.tools.conformanceTools/src/org/universaal/tools/conformanceTools/utils/RunPlugin.java @@ -5,5 +5,4 @@ public enum RunPlugin { FileConformance, CodeStyle, CustomChecks; - } \ No newline at end of file diff --git a/conformance/org.universaal.tools.conformanceTools/src/org/universaal/tools/conformanceTools/windows/MainFrame.java b/conformance/org.universaal.tools.conformanceTools/src/org/universaal/tools/conformanceTools/windows/MainFrame.java index 659a494716554e1d1b13fa77e8cea4b965895391..1b7c866c20639f2132fa14aaa7b361e09eaff4e2 100644 --- a/conformance/org.universaal.tools.conformanceTools/src/org/universaal/tools/conformanceTools/windows/MainFrame.java +++ b/conformance/org.universaal.tools.conformanceTools/src/org/universaal/tools/conformanceTools/windows/MainFrame.java @@ -47,7 +47,7 @@ public class MainFrame { cs.setLayoutData(data); Button uaal = new Button(shell, SWT.PUSH); - uaal.setText("Check against uAAL custom rules"); + uaal.setText("Check against uAAL rules"); uaal.setEnabled(true); uaal.addMouseListener(new MouseListener() { @@ -65,7 +65,7 @@ public class MainFrame { } }); uaal.setLayoutData(data); - + Button fc = new Button(shell, SWT.PUSH); fc.setText("Check proper project structure"); fc.setEnabled(true);