List of usage examples for org.apache.maven.artifact.handler ArtifactHandler getLanguage
String getLanguage();
From source file:com.alibaba.citrus.maven.eclipse.base.eclipse.EclipsePlugin.java
License:Apache License
/** @see org.apache.maven.plugin.Mojo#execute() */ public final boolean setup() throws MojoExecutionException { boolean ready = true; checkDeprecations();/*from ww w. ja va2 s.c o m*/ setProjectNameTemplate(IdeUtils.calculateProjectNameTemplate(getProjectNameTemplate(), isAddVersionToProjectName(), isAddGroupIdToProjectName(), getLog())); ajdt = enableAjdt(executedProject) && !ajdtVersion.equals("none"); ready = validate(); // TODO: Why are we using project in some places, and executedProject in others?? ArtifactHandler artifactHandler = project.getArtifact().getArtifactHandler(); // ear projects don't contain java sources // pde projects are always java projects isJavaProject = pde || (Constants.LANGUAGE_JAVA.equals(artifactHandler.getLanguage()) && !Constants.PROJECT_PACKAGING_EAR.equals(packaging)); if (sourceIncludes == null) { sourceIncludes = new ArrayList(); } if (isJavaProject) { sourceIncludes.add(JAVA_FILE_PATTERN); } if (ajdt) { sourceIncludes.add(ASPECTJ_FILE_PATTERN); } if (sourceExcludes == null) { sourceExcludes = new ArrayList(); } setupExtras(); parseConfigurationOptions(); // defaults if (projectnatures == null) { fillDefaultNatures(packaging); } if (additionalProjectnatures != null) { projectnatures.addAll(additionalProjectnatures); } if (buildcommands == null) { fillDefaultBuilders(packaging); } else { convertBuildCommandList(buildcommands); } if (additionalBuildcommands != null) { convertBuildCommandList(additionalBuildcommands); buildcommands.addAll(additionalBuildcommands); } if (classpathContainers == null) { fillDefaultClasspathContainers(packaging); } else { verifyClasspathContainerListIsComplete(); } if (linkedResources == null) { linkedResources = new ArrayList(); } locator.addSearchPath(FileResourceLoader.ID, project.getFile().getParentFile().getAbsolutePath()); locator.setOutputDirectory(new File(project.getBuild().getDirectory())); // ready to start return ready; }
From source file:com.atlassian.maven.plugin.clover.CloverInstrumentInternalMojo.java
License:Apache License
private boolean isJavaProject() { final ArtifactHandler artifactHandler = getProject().getArtifact().getArtifactHandler(); if (!"java".equals(artifactHandler.getLanguage())) { getLog().debug("The reported language of this project is " + artifactHandler.getLanguage() + ", attempting to instrument sources anyway."); }/*from ww w. j a v a 2 s . com*/ return true; }
From source file:com.rebaze.maven.support.AetherUtils.java
License:Open Source License
public static ArtifactType newArtifactType(String id, ArtifactHandler handler) { return new DefaultArtifactType(id, handler.getExtension(), handler.getClassifier(), handler.getLanguage(), handler.isAddedToClasspath(), handler.isIncludesDependencies()); }
From source file:de.andrena.tools.macker.plugin.AbstractMackerMojo.java
License:Apache License
/** * @throws MojoExecutionException/*from ww w .j ava 2 s. com*/ * if a error occurs during Macker execution * @throws MojoFailureException * if Macker detects a failure. * @see org.apache.maven.plugin.Mojo#execute() */ @Override public void execute() throws MojoExecutionException, MojoFailureException { if (skip) { return; } final ArtifactHandler artifactHandler = project.getArtifact().getArtifactHandler(); if (!"java".equals(artifactHandler.getLanguage())) { if (!quiet) { getLog().info("Not executing macker as the project is not a Java classpath-capable package"); } return; } // configure ResourceManager locator.addSearchPath(FileResourceLoader.ID, project.getFile().getParentFile().getAbsolutePath()); locator.addSearchPath("url", ""); locator.setOutputDirectory(new File(project.getBuild().getDirectory())); // check if rules were specified if (null == rules || 0 == rules.length) { rules = new String[1]; // at least the default name rules[0] = rule; } // check if there are class files to analyze List<File> files; try { files = getFilesToProcess(); } catch (final IOException e) { throw new MojoExecutionException("Error during Macker execution: error in file selection", e); } if (files == null || files.size() == 0) { // no class file, we can't do anything if (!quiet) { if (includeTests) { getLog().info( "No class files in directories " + classesDirectory + ", " + testClassesDirectory); } else { getLog().info("No class files in specified directory " + classesDirectory); } } } else { if (!outputDirectory.exists()) { if (!outputDirectory.mkdirs()) { throw new MojoExecutionException("Error during Macker execution: Could not create directory " + outputDirectory.getAbsolutePath()); } } // let's go! final File outputFile = new File(outputDirectory, outputName); launchMacker(outputFile, files); } }
From source file:de.andrena.tools.macker.plugin.MackerMojo.java
License:Apache License
/** * @throws MojoExecutionException if a error occurs during Macker execution * @throws MojoFailureException if Macker detects a failure. * @see org.apache.maven.plugin.Mojo#execute() *//*from w ww. ja va 2 s .c o m*/ public void execute() throws MojoExecutionException, MojoFailureException { if (skip) { return; } ArtifactHandler artifactHandler = project.getArtifact().getArtifactHandler(); if (!"java".equals(artifactHandler.getLanguage())) { if (!quiet) { getLog().info("Not executing macker as the project is not a Java classpath-capable package"); } return; } //configure ResourceManager locator.addSearchPath(FileResourceLoader.ID, project.getFile().getParentFile().getAbsolutePath()); locator.addSearchPath("url", ""); locator.setOutputDirectory(new File(project.getBuild().getDirectory())); // check if rules were specified if (null == rules || 0 == rules.length) { rules = new String[1]; // at least the default name rules[0] = rule; } // check if there are class files to analyze List/*<File>*/ files; try { files = getFilesToProcess(); } catch (IOException e) { throw new MojoExecutionException("Error during Macker execution: error in file selection", e); } if (files == null || files.size() == 0) { // no class file, we can't do anything if (!quiet) { if (includeTests) { getLog().info( "No class files in directories " + classesDirectory + ", " + testClassesDirectory); } else { getLog().info("No class files in specified directory " + classesDirectory); } } } else { if (!outputDirectory.exists()) { if (!outputDirectory.mkdirs()) { throw new MojoExecutionException("Error during Macker execution: Could not create directory " + outputDirectory.getAbsolutePath()); } } // let's go! File outputFile = new File(outputDirectory, outputName); launchMacker(outputFile, files); } }
From source file:de.zalando.mojo.aspectj.AbstractAjcCompiler.java
License:Open Source License
/** * Do the AspectJ compiling./*from w w w .ja v a2s .co m*/ * * @throws MojoExecutionException */ @SuppressWarnings("unchecked") public void execute() throws MojoExecutionException { if (isSkip()) { if (getLog().isInfoEnabled()) { getLog().info("Skipping execution because of 'skip' option"); } return; } ArtifactHandler artifactHandler = project.getArtifact().getArtifactHandler(); if (!"java".equalsIgnoreCase(artifactHandler.getLanguage())) { getLog().warn("Not executing aspectJ compiler as the project is not a Java classpath-capable package"); return; } // MASPECT-110: // // Only add the aspectSourcePathDir and testAspectSourcePathDir to their respective // compileSourceRoots if they actually exist and are directories... to avoid crashing // downstream plugins requiring/assuming that all entries within the compileSourceRoots // and testCompileSourceRoots are directories. // final File aspectSourcePathDir = FileUtils.resolveFile(basedir, aspectDirectory); final File testAspectSourcePathDir = FileUtils.resolveFile(basedir, testAspectDirectory); final String aspectSourcePath = aspectSourcePathDir.getAbsolutePath(); final String testAspectSourcePath = testAspectSourcePathDir.getAbsolutePath(); if (aspectSourcePathDir.exists() && aspectSourcePathDir.isDirectory() && !project.getCompileSourceRoots().contains(aspectSourcePath)) { getLog().debug("Adding existing aspectSourcePathDir [" + aspectSourcePath + "] to compileSourceRoots."); project.getCompileSourceRoots().add(aspectSourcePath); } else { getLog().debug("Not adding non-existent or already added aspectSourcePathDir [" + aspectSourcePath + "] to compileSourceRoots."); } if (testAspectSourcePathDir.exists() && testAspectSourcePathDir.isDirectory() && !project.getTestCompileSourceRoots().contains(testAspectSourcePath)) { getLog().debug("Adding existing testAspectSourcePathDir [" + testAspectSourcePath + "] to testCompileSourceRoots."); project.getTestCompileSourceRoots().add(testAspectSourcePath); } else { getLog().debug("Not adding non-existent or already added testAspectSourcePathDir [" + testAspectSourcePath + "] to testCompileSourceRoots."); } assembleArguments(); if (!forceAjcCompile && !hasSourcesToCompile()) { getLog().warn("No sources found skipping aspectJ compile"); return; } if (!forceAjcCompile && !isBuildNeeded()) { getLog().info("No modifications found skipping aspectJ compile"); return; } if (getLog().isDebugEnabled()) { StringBuilder command = new StringBuilder("Running : ajc"); for (String arg : ajcOptions) { command.append(' ').append(arg); } getLog().debug(command); } try { getLog().debug( "Compiling and weaving " + resolvedIncludes.size() + " sources to " + getOutputDirectory()); AjcHelper.writeBuildConfigToFile(ajcOptions, argumentFileName, getOutputDirectory()); getLog().debug("Arguments file written : " + new File(getOutputDirectory(), argumentFileName).getAbsolutePath()); } catch (IOException e) { throw new MojoExecutionException("Could not write arguments file to the target area", e); } final Main ajcMain = new Main(); MavenMessageHandler mavenMessageHandler = new MavenMessageHandler(getLog()); ajcMain.setHolder(mavenMessageHandler); synchronized (BIG_ASPECTJ_LOCK) { ajcMain.runMain((String[]) ajcOptions.toArray(new String[ajcOptions.size()]), false); } IMessage[] errors = mavenMessageHandler.getMessages(IMessage.ERROR, true); if (!proceedOnError && errors.length > 0) { throw CompilationFailedException.create(errors); } }
From source file:de.zalando.mojo.aspectj.AjcReportMojo.java
License:Open Source License
/** * @see org.apache.maven.reporting.AbstractMavenReport#canGenerateReport() *//* w w w. ja v a 2 s. c om*/ public boolean canGenerateReport() { // Only execute reports for java projects ArtifactHandler artifactHandler = this.project.getArtifact().getArtifactHandler(); return "java".equals(artifactHandler.getLanguage()); }
From source file:org.apache.nifi.NarProvidedDependenciesMojo.java
License:Apache License
/** * Creates a new ArtifactHandler for the specified Artifact that overrides the includeDependencies flag. When set, this flag prevents transitive * dependencies from being printed in dependencies plugin. * * @param artifact The artifact// w w w . ja v a 2 s .c o m * @return The handler for the artifact */ private ArtifactHandler excludesDependencies(final Artifact artifact) { final ArtifactHandler orig = artifact.getArtifactHandler(); return new ArtifactHandler() { @Override public String getExtension() { return orig.getExtension(); } @Override public String getDirectory() { return orig.getDirectory(); } @Override public String getClassifier() { return orig.getClassifier(); } @Override public String getPackaging() { return orig.getPackaging(); } // mark dependencies has excluded so they will appear in tree listing @Override public boolean isIncludesDependencies() { return false; } @Override public String getLanguage() { return orig.getLanguage(); } @Override public boolean isAddedToClasspath() { return orig.isAddedToClasspath(); } }; }
From source file:org.apache.tuscany.maven.plugin.eclipse.EclipsePlugin.java
License:Apache License
/** * @see org.apache.maven.plugin.Mojo#execute() */// w w w.j a va 2 s .c om public final boolean setup() throws MojoExecutionException { boolean ready = true; checkDeprecations(); setProjectNameTemplate(IdeUtils.calculateProjectNameTemplate(getProjectNameTemplate(), isAddVersionToProjectName(), isAddGroupIdToProjectName(), getLog())); ajdt = enableAjdt(executedProject) && !ajdtVersion.equals("none"); ready = validate(); // TODO: Why are we using project in some places, and executedProject in others?? ArtifactHandler artifactHandler = project.getArtifact().getArtifactHandler(); // ear projects don't contain java sources // pde projects are always java projects isJavaProject = pde || (Constants.LANGUAGE_JAVA.equals(artifactHandler.getLanguage()) && !Constants.PROJECT_PACKAGING_EAR.equals(packaging)); setupExtras(); parseConfigurationOptions(); // defaults if (projectnatures == null) { fillDefaultNatures(packaging); } if (additionalProjectnatures != null) { projectnatures.addAll(additionalProjectnatures); } if (buildcommands == null) { fillDefaultBuilders(packaging); } else { convertBuildCommandList(buildcommands); } if (additionalBuildcommands != null) { convertBuildCommandList(additionalBuildcommands); buildcommands.addAll(additionalBuildcommands); } if (classpathContainers == null) { fillDefaultClasspathContainers(packaging); } else { verifyClasspathContainerListIsComplete(); } locator.addSearchPath(FileResourceLoader.ID, project.getFile().getParentFile().getAbsolutePath()); locator.setOutputDirectory(new File(project.getBuild().getDirectory())); // ready to start return ready; }
From source file:org.codecover.mojo.InstrumentMojo.java
License:Apache License
public void execute() throws MojoExecutionException { ArtifactHandler artifactHandler = project.getArtifact().getArtifactHandler(); if (!"java".equals(artifactHandler.getLanguage())) { getLog().info("Not executing codecover:instrument as the project is not a java project."); return;/*from w w w . ja v a 2s . c o m*/ } buildDirectory = new File(project.getBuild().getDirectory()); if (!buildDirectory.exists()) { buildDirectory.mkdirs(); } generatedSourcesDirectory = new File(buildDirectory, "codecover/generated-sources"); if (!generatedSourcesDirectory.exists()) { generatedSourcesDirectory.mkdirs(); } generatedClassesDirectory = new File(buildDirectory, "codecover/generated-classes"); if (!generatedClassesDirectory.exists()) { generatedClassesDirectory.mkdirs(); } sourceDirectory = new File(project.getBuild().getSourceDirectory()); try { FileUtils.copyDirectoryStructure(sourceDirectory, generatedSourcesDirectory); } catch (IOException e) { throw new MojoExecutionException("Unable to prepare instrumentation directory.", e); } PluginManager pluginManager = PluginManager.create(); PluginHandle javaPluginHandle = PluginHandle.createPluginHandle( "org.codecover.instrumentation.java15.InstrumenterDescriptor", 0, 1, new InstrumenterPlugin()); pluginManager.addPlugin(javaPluginHandle); setPluginManager(pluginManager); setLogger(new SimpleLogger()); run(); project.getCompileSourceRoots().clear(); project.addCompileSourceRoot(generatedSourcesDirectory.getPath()); //project.getBuild().setSourceDirectory(); //System.setProperty("project.build.sourceDirectory", generatedSourcesDirectory.getPath()); }