org.apache.maven.artifact.handler.ArtifactHandler Java Examples
The following examples show how to use
org.apache.maven.artifact.handler.ArtifactHandler.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: FlatRepositoryLayout.java From appassembler with MIT License | 6 votes |
public String pathOf( Artifact artifact ) { ArtifactHandler artifactHandler = artifact.getArtifactHandler(); StringBuilder path = new StringBuilder(); path.append( artifact.getArtifactId() ).append( ARTIFACT_SEPARATOR ).append( artifact.getVersion() ); if ( artifact.hasClassifier() ) { path.append( ARTIFACT_SEPARATOR ).append( artifact.getClassifier() ); } if ( artifactHandler.getExtension() != null && artifactHandler.getExtension().length() > 0 ) { path.append( GROUP_SEPARATOR ).append( artifactHandler.getExtension() ); } return path.toString(); }
Example #2
Source File: MavenUtils.java From mvn-golang with Apache License 2.0 | 6 votes |
/** * Parse string containing artifact record * * @param record string containing record, must not be null * @param handler artifact handler for created artifact, must not be null * @return new created artifact from the record, must not be null * @throws InvalidVersionSpecificationException it will be thrown if version * format is wrong * @throws IllegalArgumentException it will be thrown if record can't be * recognized as artifact record */ @Nonnull public static Artifact parseArtifactRecord( @Nonnull final String record, @Nonnull final ArtifactHandler handler ) throws InvalidVersionSpecificationException { final Matcher matcher = ARTIFACT_RECORD_PATTERN.matcher(record.trim()); if (matcher.find()) { return new DefaultArtifact( matcher.group(1), matcher.group(2), VersionRange.createFromVersion(matcher.group(3)), matcher.group(4).isEmpty() ? null : matcher.group(4), matcher.group(5).isEmpty() ? null : matcher.group(5), matcher.group(6).isEmpty() ? null : matcher.group(6), handler); } throw new IllegalArgumentException("Can't recognize record as artifact: " + record); }
Example #3
Source File: NativeRanlibMojoTest.java From maven-native with MIT License | 6 votes |
public void testMojoLookup() throws Exception { File pluginXml = new File( getBasedir(), "src/test/resources/linker/plugin-config-ranlib.xml" ); NativeRanlibMojo mojo = (NativeRanlibMojo) lookupMojo( "ranlib", pluginXml ); assertNotNull( mojo ); // simulate artifact ArtifactHandler artifactHandler = new DefaultArtifactHandler(); Artifact artifact = new DefaultArtifact( "test", "test", VersionRange.createFromVersion( "1.0-SNAPSHOT" ), "compile", "exe", null, artifactHandler ); mojo.getProject().setArtifact( artifact ); mojo.execute(); }
Example #4
Source File: NativeInitializeMojoTest.java From maven-native with MIT License | 6 votes |
public void testMojoLookup() throws Exception { File pluginXml = new File( getBasedir(), "src/test/resources/initialize/plugin-config.xml" ); NativeInitializeMojo mojo = (NativeInitializeMojo) lookupMojo( "initialize", pluginXml ); assertNotNull( mojo ); // simulate artifact ArtifactHandler artifactHandler = new DefaultArtifactHandler(); Artifact artifact = new DefaultArtifact( "test", "test", VersionRange.createFromVersion( "1.0-SNAPSHOT" ), "compile", "exe", null, artifactHandler ); mojo.project.setArtifact( artifact ); mojo.setPluginContext( new HashMap<>() ); mojo.execute(); assertEquals( "someArtifactId", mojo.project.getBuild().getFinalName() ); }
Example #5
Source File: NativeLinkerMojoTest.java From maven-native with MIT License | 5 votes |
public void testExecuteWithFinalNameExtension() throws Exception { NativeLinkMojo mojo = getMojo(); // simulate object files List<File> objectList = new ArrayList<>(); objectList.add( new File( "o1.o" ) ); objectList.add( new File( "o2.o" ) ); mojo.saveCompilerOutputFilePaths( objectList ); // simulate artifact ArtifactHandler artifactHandler = new DefaultArtifactHandler(); Artifact artifact = new DefaultArtifact( "test", "test", VersionRange.createFromVersion( "1.0-SNAPSHOT" ), "compile", "exe", null, artifactHandler ); mojo.getProject().setArtifact( artifact ); // simulate artifacts mojo.getProject().setArtifacts( new HashSet<Artifact>() ); // no extern libs for now String linkerFinalName = "some-final-name"; setVariableValueToObject( mojo, "linkerFinalName", linkerFinalName ); String linkerFinalNameExt = "some-extension"; setVariableValueToObject( mojo, "linkerFinalNameExt", linkerFinalNameExt ); mojo.execute(); LinkerConfiguration conf = mojo.getLgetLinkerConfiguration(); // "target is set in the stub assertEquals( new File( "target" ), conf.getOutputDirectory() ); assertEquals( linkerFinalName, conf.getOutputFileName() ); assertEquals( linkerFinalNameExt, conf.getOutputFileExtension() ); assertEquals( new File( "target/some-final-name.some-extension" ), conf.getOutputFile() ); }
Example #6
Source File: ArtifactUtils.java From appassembler with MIT License | 5 votes |
/** * get relative path the copied artifact using base version. This is mainly use to SNAPSHOT instead of timestamp in * the file name * * @param artifactRepositoryLayout {@link ArtifactRepositoryLayout} * @param artifact {@link Artifact} * @return The base version. */ public static String pathBaseVersionOf( ArtifactRepositoryLayout artifactRepositoryLayout, Artifact artifact ) { ArtifactHandler artifactHandler = artifact.getArtifactHandler(); StringBuilder fileName = new StringBuilder(); fileName.append( artifact.getArtifactId() ).append( "-" ).append( artifact.getBaseVersion() ); if ( artifact.hasClassifier() ) { fileName.append( "-" ).append( artifact.getClassifier() ); } if ( artifactHandler.getExtension() != null && artifactHandler.getExtension().length() > 0 ) { fileName.append( "." ).append( artifactHandler.getExtension() ); } String relativePath = artifactRepositoryLayout.pathOf( artifact ); String[] tokens = StringUtils.split( relativePath, "/" ); tokens[tokens.length - 1] = fileName.toString(); StringBuilder path = new StringBuilder(); for ( int i = 0; i < tokens.length; ++i ) { path.append( tokens[i] ); if ( i != tokens.length - 1 ) { path.append( "/" ); } } return path.toString(); }
Example #7
Source File: CompilerMojoTestBase.java From aspectj-maven-plugin with MIT License | 5 votes |
/** * */ protected void setUp() throws Exception { // prepare plexus environment super.setUp(); ajcMojo.project = project; String temp = new File( "." ).getAbsolutePath(); basedir = temp.substring( 0, temp.length() - 2 ) + "/src/test/projects/" + getProjectName() + "/"; project.getBuild().setDirectory( basedir + "/target" ); project.getBuild().setOutputDirectory( basedir + "/target/classes" ); project.getBuild().setTestOutputDirectory( basedir + "/target/test-classes" ); project.getBuild().setSourceDirectory( basedir + "/src/main/java" ); project.getBuild().setTestSourceDirectory( basedir + "/src/test/java" ); project.addCompileSourceRoot( project.getBuild().getSourceDirectory() ); project.addTestCompileSourceRoot( project.getBuild().getTestSourceDirectory() ); ajcMojo.basedir = new File( basedir ); setVariableValueToObject( ajcMojo, "outputDirectory", new File( project.getBuild().getOutputDirectory() ) ); setVariableValueToObject( ajcMojo, "generatedSourcesDirectory", new File( project.getBuild().getDirectory() + "/generated-sources/annotations" ) ); ArtifactHandler artifactHandler = new MockArtifactHandler(); Artifact artifact = new MockArtifact( "dill", "dall" ); artifact.setArtifactHandler( artifactHandler ); project.setArtifact( artifact ); project.setDependencyArtifacts( Collections.emptySet() ); }
Example #8
Source File: AetherUtils.java From takari-lifecycle with Eclipse Public License 1.0 | 5 votes |
public static ArtifactHandler newHandler(Artifact artifact) { String type = artifact.getProperty(ArtifactProperties.TYPE, artifact.getExtension()); DefaultArtifactHandler handler = new DefaultArtifactHandler(type); handler.setExtension(artifact.getExtension()); handler.setLanguage(artifact.getProperty(ArtifactProperties.LANGUAGE, null)); handler.setAddedToClasspath(Boolean.parseBoolean(artifact.getProperty(ArtifactProperties.CONSTITUTES_BUILD_PATH, ""))); handler.setIncludesDependencies(Boolean.parseBoolean(artifact.getProperty(ArtifactProperties.INCLUDES_DEPENDENCIES, ""))); return handler; }
Example #9
Source File: ExternalBomResolver.java From sundrio with Apache License 2.0 | 5 votes |
public ExternalBomResolver(MavenSession mavenSession, ArtifactHandler artifactHandler, RepositorySystem system, RepositorySystemSession session, List<RemoteRepository> remoteRepositories, Log logger) { this.mavenSession = mavenSession; this.artifactHandler = artifactHandler; this.system = system; this.session = session; this.remoteRepositories = remoteRepositories; this.logger = logger; }
Example #10
Source File: AjcReportMojo.java From aspectj-maven-plugin with MIT License | 5 votes |
/** * @see org.apache.maven.reporting.AbstractMavenReport#canGenerateReport() */ public boolean canGenerateReport() { // Only execute reports for java projects ArtifactHandler artifactHandler = this.project.getArtifact().getArtifactHandler(); return "java".equals( artifactHandler.getLanguage() ); }
Example #11
Source File: CreateEffectivePomTest.java From flatten-maven-plugin with Apache License 2.0 | 5 votes |
/** * Tests method to create effective POM. * * @throws Exception if something goes wrong. */ @Test public void testCreateEffectivePom() throws Exception { String magicValue = "magic-value"; Properties userProperties = new Properties(); userProperties.setProperty( "cmd.test.property", magicValue ); File pomFile = new File( "src/test/resources/cmdpropertysubstituion/pom.xml" ); ArtifactRepository localRepository = new MavenArtifactRepository(); localRepository.setLayout( new DefaultRepositoryLayout() ); ArtifactFactory artifactFactory = new DefaultArtifactFactory(); ArtifactHandlerManager artifactHandlerManager = new DefaultArtifactHandlerManager(); setDeclaredField( artifactFactory, "artifactHandlerManager", artifactHandlerManager ); Map<String, ArtifactHandler> artifactHandlers = new HashMap<String, ArtifactHandler>(); setDeclaredField( artifactHandlerManager, "artifactHandlers", artifactHandlers ); DefaultDependencyResolver depencencyResolver = new DefaultDependencyResolver(); DefaultProjectBuildingRequest projectBuildingRequest = new DefaultProjectBuildingRequest(); FlattenModelResolver resolver = new FlattenModelResolver( localRepository, artifactFactory, depencencyResolver, projectBuildingRequest, Collections.<MavenProject>emptyList() ); ModelBuildingRequest buildingRequest = new DefaultModelBuildingRequest().setPomFile( pomFile ).setModelResolver( resolver ).setUserProperties( userProperties ); setDeclaredField( tested, "modelBuilderThreadSafetyWorkaround", buildModelBuilderThreadSafetyWorkaroundForTest() ); Model effectivePom = tested.createEffectivePom( buildingRequest, false, FlattenMode.defaults ); assertThat( effectivePom.getName() ).isEqualTo( magicValue ); }
Example #12
Source File: NativeLinkerMojoTest.java From maven-native with MIT License | 5 votes |
public void testExecute() throws Exception { NativeLinkMojo mojo = getMojo(); // simulate object files List<File> objectList = new ArrayList<>(); objectList.add( new File( "o1.o" ) ); objectList.add( new File( "o2.o" ) ); mojo.saveCompilerOutputFilePaths( objectList ); // simulate artifact ArtifactHandler artifactHandler = new DefaultArtifactHandler(); Artifact artifact = new DefaultArtifact( "test", "test", VersionRange.createFromVersion( "1.0-SNAPSHOT" ), "compile", "exe", null, artifactHandler ); mojo.getProject().setArtifact( artifact ); // simulate artifacts mojo.getProject().setArtifacts( new HashSet<Artifact>() ); // no extern libs for now String linkerFinalName = "some-final-name"; setVariableValueToObject( mojo, "linkerFinalName", linkerFinalName ); mojo.execute(); LinkerConfiguration conf = mojo.getLgetLinkerConfiguration(); // "target is set in the stub assertEquals( new File( "target" ), conf.getOutputDirectory() ); assertEquals( linkerFinalName, conf.getOutputFileName() ); assertNull( conf.getOutputFileExtension() ); // current artifactHandler mocking return null extension name assertEquals( new File( "target/some-final-name.null" ), conf.getOutputFile() ); }
Example #13
Source File: AbstractMavenEventHandler.java From pipeline-maven-plugin with MIT License | 5 votes |
public Xpp3Dom newElement(@Nonnull String name, @Nullable Artifact artifact) { Xpp3Dom element = new Xpp3Dom(name); if (artifact == null) { return element; } element.setAttribute("groupId", artifact.getGroupId()); element.setAttribute("artifactId", artifact.getArtifactId()); element.setAttribute("baseVersion", artifact.getBaseVersion()); element.setAttribute("version", artifact.getVersion()); element.setAttribute("snapshot", String.valueOf(artifact.isSnapshot())); if (artifact.getClassifier() != null) { element.setAttribute("classifier", artifact.getClassifier()); } element.setAttribute("type", artifact.getType()); element.setAttribute("id", artifact.getId()); ArtifactHandler artifactHandler = artifact.getArtifactHandler(); String extension; if (artifactHandler == null) { extension = artifact.getType(); } else { extension = artifactHandler.getExtension(); } element.setAttribute("extension", extension); return element; }
Example #14
Source File: TestPropertiesMojoTest.java From takari-lifecycle with Eclipse Public License 1.0 | 5 votes |
private MojoExecution newMojoExecution(Xpp3Dom... parameters) throws IOException { MojoExecution execution = mojos.newMojoExecution("testProperties", parameters); PluginDescriptor pluginDescriptor = execution.getMojoDescriptor().getPluginDescriptor(); ArtifactHandler handler = new DefaultArtifactHandler("jar"); DefaultArtifact workspaceResolver = new DefaultArtifact("io.takari.m2e.workspace", "org.eclipse.m2e.workspace.cli", "1", Artifact.SCOPE_COMPILE, ".jar", null, handler); workspaceResolver.setFile(new File("target/workspaceResolver.jar").getCanonicalFile()); List<Artifact> pluginArtifacts = new ArrayList<>(pluginDescriptor.getArtifacts()); pluginArtifacts.add(workspaceResolver); pluginDescriptor.setArtifacts(pluginArtifacts); return execution; }
Example #15
Source File: PackageMojo.java From vertx-maven-plugin with Apache License 2.0 | 5 votes |
private void attachIfNeeded(File jar) { if (jar.isFile() && classifier != null && attach) { ArtifactHandler handler = new DefaultArtifactHandler("jar"); Artifact vertxJarArtifact = new DefaultArtifact(project.getGroupId(), project.getArtifactId(), project.getVersion(), "compile", "jar", classifier, handler); vertxJarArtifact.setFile(jar); this.project.addAttachedArtifact(vertxJarArtifact); } }
Example #16
Source File: Classpath.java From wisdom with Apache License 2.0 | 4 votes |
@Override public ArtifactHandler deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException { return mapper.readValue(jp, DefaultArtifactHandler.class); }
Example #17
Source File: NarProvidedDependenciesMojo.java From nifi-maven with Apache License 2.0 | 4 votes |
@Override public void execute() throws MojoExecutionException, MojoFailureException { try { // find the nar dependency Artifact narArtifact = null; for (final Artifact artifact : project.getDependencyArtifacts()) { if (NAR.equals(artifact.getType())) { // ensure the project doesn't have two nar dependencies if (narArtifact != null) { throw new MojoExecutionException("Project can only have one NAR dependency."); } // record the nar dependency narArtifact = artifact; } } // ensure there is a nar dependency if (narArtifact == null) { throw new MojoExecutionException("Project does not have any NAR dependencies."); } // build the project for the nar artifact final ProjectBuildingRequest narRequest = new DefaultProjectBuildingRequest(); narRequest.setRepositorySession(repoSession); narRequest.setSystemProperties(System.getProperties()); final ProjectBuildingResult narResult = projectBuilder.build(narArtifact, narRequest); narRequest.setProject(narResult.getProject()); // get the artifact handler for excluding dependencies final ArtifactHandler narHandler = excludesDependencies(narArtifact); narArtifact.setArtifactHandler(narHandler); // nar artifacts by nature includes dependencies, however this prevents the // transitive dependencies from printing using tools like dependency:tree. // here we are overriding the artifact handler for all nars so the // dependencies can be listed. this is important because nar dependencies // will be used as the parent classloader for this nar and seeing what // dependencies are provided is critical. final Map<String, ArtifactHandler> narHandlerMap = new HashMap<>(); narHandlerMap.put(NAR, narHandler); artifactHandlerManager.addHandlers(narHandlerMap); // get the dependency tree final DependencyNode root = dependencyGraphBuilder.buildDependencyGraph(narRequest, null); // write the appropriate output DependencyNodeVisitor visitor = null; if ("tree".equals(mode)) { visitor = new TreeWriter(); } else if ("pom".equals(mode)) { visitor = new PomWriter(); } // ensure the mode was specified correctly if (visitor == null) { throw new MojoExecutionException("The specified mode is invalid. Supported options are 'tree' and 'pom'."); } // visit and print the results root.accept(visitor); getLog().info("--- Provided NAR Dependencies ---\n\n" + visitor.toString()); } catch (ProjectBuildingException | DependencyGraphBuilderException e) { throw new MojoExecutionException("Cannot build project dependency tree", e); } }
Example #18
Source File: NarProvidedDependenciesMojo.java From nifi-maven with Apache License 2.0 | 4 votes |
/** * 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 * @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(); } }; }
Example #19
Source File: AetherUtils.java From takari-lifecycle with Eclipse Public License 1.0 | 4 votes |
public static ArtifactType newArtifactType(String id, ArtifactHandler handler) { return new DefaultArtifactType(id, handler.getExtension(), handler.getClassifier(), handler.getLanguage(), handler.isAddedToClasspath(), handler.isIncludesDependencies()); }
Example #20
Source File: AetherUtils.java From takari-lifecycle with Eclipse Public License 1.0 | 4 votes |
public ArtifactType get(String stereotypeId) { ArtifactHandler handler = handlerManager.getArtifactHandler(stereotypeId); return newArtifactType(stereotypeId, handler); }
Example #21
Source File: AbstractSundrioMojo.java From sundrio with Apache License 2.0 | 4 votes |
public ArtifactHandler getArtifactHandler() { return artifactHandler; }
Example #22
Source File: PackageMojo.java From ARCHIVE-wildfly-swarm with Apache License 2.0 | 4 votes |
@Override public void execute() throws MojoExecutionException, MojoFailureException { initProperties(false); final BuildTool tool = new BuildTool(); tool.projectArtifact( this.project.getArtifact().getGroupId(), this.project.getArtifact().getArtifactId(), this.project.getArtifact().getBaseVersion(), this.project.getArtifact().getType(), this.project.getArtifact().getFile()); this.project.getArtifacts() .forEach(dep -> tool.dependency(dep.getScope(), dep.getGroupId(), dep.getArtifactId(), dep.getBaseVersion(), dep.getType(), dep.getClassifier(), dep.getFile(), dep.getDependencyTrail().size() == 2)); List<Resource> resources = this.project.getResources(); for (Resource each : resources) { tool.resourceDirectory(each.getDirectory()); } for (String additionalModule : additionalModules) { File source = new File(this.project.getBuild().getOutputDirectory(), additionalModule); if (source.exists()) { tool.additionalModule(source.getAbsolutePath()); } } tool .properties(this.properties) .mainClass(this.mainClass) .bundleDependencies(this.bundleDependencies); MavenArtifactResolvingHelper resolvingHelper = new MavenArtifactResolvingHelper(this.resolver, this.repositorySystem, this.repositorySystemSession); this.remoteRepositories.forEach(resolvingHelper::remoteRepository); tool.artifactResolvingHelper(resolvingHelper); try { File jar = tool.build(this.project.getBuild().getFinalName(), Paths.get(this.projectBuildDir)); Artifact primaryArtifact = this.project.getArtifact(); ArtifactHandler handler = new DefaultArtifactHandler("jar"); Artifact swarmJarArtifact = new DefaultArtifact( primaryArtifact.getGroupId(), primaryArtifact.getArtifactId(), primaryArtifact.getBaseVersion(), primaryArtifact.getScope(), "jar", "swarm", handler ); swarmJarArtifact.setFile(jar); this.project.addAttachedArtifact(swarmJarArtifact); } catch (Exception e) { throw new MojoFailureException("Unable to create -swarm.jar", e); } }
Example #23
Source File: MockArtifact.java From aspectj-maven-plugin with MIT License | 4 votes |
public void setArtifactHandler( ArtifactHandler artifactHandler ) { this.artifactHandler = artifactHandler; }
Example #24
Source File: MockArtifact.java From aspectj-maven-plugin with MIT License | 4 votes |
public ArtifactHandler getArtifactHandler() { return artifactHandler; }
Example #25
Source File: AbstractAjcCompiler.java From aspectj-maven-plugin with MIT License | 4 votes |
/** * Do the AspectJ compiling. * * @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 (!forceAjcCompile && !"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(ajcOptions.toArray(new String[ajcOptions.size()]), false); } IMessage[] errors = mavenMessageHandler.getMessages(IMessage.ERROR, true); if (!proceedOnError && errors.length > 0) { throw CompilationFailedException.create(errors); } }
Example #26
Source File: PackageMojo.java From vertx-maven-plugin with Apache License 2.0 | 4 votes |
@Override public void execute() throws MojoExecutionException, MojoFailureException { if (skip) { getLog().info("vertx:package skipped by configuration"); return; } // Fix empty classifier. if (classifier != null && classifier.trim().isEmpty()) { getLog().debug("The classifier is empty, it won't be used"); classifier = null; } if (classifier == null && !attach) { throw new MojoExecutionException("Cannot disable attachment of the created archive when it's the main " + "artifact"); } //TODO Archive should be a parameter. Archive archive = ServiceUtils.getDefaultFatJar(); if (launcher != null && !launcher.trim().isEmpty()) { archive.getManifest().putIfAbsent("Main-Class", launcher); } if (verticle != null && !verticle.trim().isEmpty()) { archive.getManifest().putIfAbsent("Main-Verticle", verticle); } List<ManifestCustomizerService> customizers = getManifestCustomizers(); customizers.forEach(customizer -> archive.getManifest().putAll(customizer.getEntries(this, project))); // Manage SPI combination combiner.doCombine(new ServiceFileCombinationConfig() .setStrategy(serviceProviderCombination) .setProject(project) .setArchive(archive) .setMojo(this) .setArtifacts(project.getArtifacts())); File jar; try { jar = packageService.doPackage( new PackageConfig() .setArtifacts(project.getArtifacts()) .setMojo(this) .setOutput(new File(projectBuildDir, computeOutputName(project, classifier))) .setProject(project) .setArchive(archive)); } catch (PackagingException e) { throw new MojoExecutionException("Unable to build the fat jar", e); } if (jar.isFile() && classifier != null && attach) { ArtifactHandler handler = new DefaultArtifactHandler("jar"); Artifact vertxJarArtifact = new DefaultArtifact(project.getGroupId(), project.getArtifactId(), project.getVersion(), "compile", "jar", classifier, handler); vertxJarArtifact.setFile(jar); this.project.addAttachedArtifact(vertxJarArtifact); } }
Example #27
Source File: Archetype.java From netbeans with Apache License 2.0 | 4 votes |
/** * initially non resolved artifact, need to call resolveArtifacts() before getArtifact().getFile() can be used. * @return */ public synchronized Artifact getArtifact() { if (artifact == null) { MavenEmbedder online = EmbedderFactory.getOnlineEmbedder(); artifact = online.createArtifact( getGroupId(), getArtifactId(), getVersion(), "jar", //NOI18N "maven-archetype"); //NOI18N //hack to get the right extension for the right packaging without the plugin. artifact.setArtifactHandler(new ArtifactHandler() { @Override public String getExtension() { return "jar"; //NOI18N } @Override public String getDirectory() { return null; } @Override public String getClassifier() { return null; } @Override public String getPackaging() { return "maven-archetype"; //NOI18N } @Override public boolean isIncludesDependencies() { return false; } @Override public String getLanguage() { return "java"; //NOI18N } @Override public boolean isAddedToClasspath() { return false; } }); } return artifact; }
Example #28
Source File: AscArtifactHandler.java From pgpverify-maven-plugin with Apache License 2.0 | 2 votes |
/** * Initializes a new ASC Artifact Handler to wrap the provided regular * artifact handler. * * The GPG signature file returned will correspond to the artifact that the * specified artifact handler resolves. * * @param wrappedHandler * An artifact handler that will be wrapped by this ASC Artifact Handler, * such that all information about the target artifact come from the * provided handler, except for the file extension (".asc"). */ AscArtifactHandler(ArtifactHandler wrappedHandler) { this.wrappedHandler = wrappedHandler; }