List of usage examples for org.apache.maven.artifact.handler DefaultArtifactHandler DefaultArtifactHandler
public DefaultArtifactHandler()
From source file:ch.sourcepond.maven.plugin.repobuilder.AdditionalArtifact.java
License:Apache License
/** * @return//from w w w. j av a 2s . c o m * @throws MojoExecutionException */ Artifact toArtifact() throws MojoExecutionException { final DefaultArtifactHandler handler = new DefaultArtifactHandler(); String extension = this.extension; if (isBlank(extension)) { extension = getFileExtension(file.getAbsolutePath()); } if (isBlank(extension)) { throw new MojoExecutionException( "No extension specified; either add an extension to the artifact-file, or, specify parameter 'extension'! Invalid config item: " + this); } handler.setExtension(extension); final Artifact artifact = new DefaultArtifact(groupId, artifactId, version, "", handler.getExtension(), classifier, handler); artifact.setFile(file); return artifact; }
From source file:com.github.born2snipe.maven.plugin.idea.BaseMojoTestCase.java
License:Apache License
protected void addProjectDependency(String definition) { String[] parts = definition.split(":"); File file = new File(mavenRepoDir, parts[1] + "-" + parts[2] + ".jar"); DefaultArtifactHandler artifactHandler = new DefaultArtifactHandler(); artifactHandler.setAddedToClasspath(true); DefaultArtifact artifact = new DefaultArtifact(parts[0], parts[1], parts[2], "compile", "jar", "main", artifactHandler);/*ww w. j av a2 s. c om*/ artifact.setFile(file); writeFile(file, definition); mavenProject.getArtifacts().add(artifact); }
From source file:com.monday_consulting.maven.plugins.fsm.util.resolver.MavenGetArtifactsResolver.java
License:Apache License
private MavenProject getMavenProjectViaRepository(final Module module, final ProjectBuilder projectBuilder) throws MojoFailureException { try {//w w w .j av a 2s . co m final ProjectBuildingRequest request = new DefaultProjectBuildingRequest(); request.setResolveDependencies(true); request.setRemoteRepositories(mavenProject.getRemoteArtifactRepositories()); request.setRepositorySession(repoSession); final LocalRepositoryManager localRepositoryManager = repoSession.getLocalRepositoryManager(); final File repoBasedir = localRepositoryManager.getRepository().getBasedir(); // the module type artifact (war, jar, pom ...) final DefaultArtifact moduleArtifact = new DefaultArtifact(module.getGroupId(), module.getArtifactId(), module.getClassifier(), module.getType(), module.getVersion()); final String pathForLocalArtifact = localRepositoryManager.getPathForLocalArtifact(moduleArtifact); final File moduleArtifactFile = new File(repoBasedir, pathForLocalArtifact); // the module pom artifact to build maven project final DefaultArtifact pomArtifact = new DefaultArtifact(module.getGroupId(), module.getArtifactId(), module.getClassifier(), "pom", module.getVersion()); final String localArtifactPath = localRepositoryManager.getPathForLocalArtifact(pomArtifact); final File projectFile = new File(repoBasedir, localArtifactPath); MavenProject result; try { log.info("try to build maven project for " + module.getArtifactId() + " from local repository..."); result = projectBuilder.build(projectFile, request).getProject(); if (!moduleArtifactFile.exists()) { resolveArtifact(module, moduleArtifact); } } catch (ProjectBuildingException e) { log.info("failed... try to resolve " + module.getArtifactId() + " from remote repository..."); final Artifact mavenArtifact = new org.apache.maven.artifact.DefaultArtifact(module.getGroupId(), module.getArtifactId(), module.getVersion(), null, module.getType(), module.getClassifier(), new DefaultArtifactHandler()); result = projectBuilder.build(mavenArtifact, request).getProject(); resolveArtifact(module, moduleArtifact); } if (result != null) { log.info("Dependency resolved: " + module.getArtifactId()); result.getArtifact().setFile(moduleArtifactFile); result.setParent(mavenProject); } else { throw new MojoFailureException( "No dependency for " + module.getArtifactId() + " found in local or remote repository"); } return result; } catch (ProjectBuildingException e) { throw new MojoFailureException( "No dependency for " + module.getArtifactId() + "found in local or remote repository", e); } }
From source file:nl.pieni.maven.dependency_analyzer.mojo.create.AbstractParserMojo.java
License:Apache License
/** * Convert a {|@link ArtifactInfo} object to a Maven project. * * @param artifactInfo The artifact//from w w w. j av a 2 s . c o m * @return A {@link org.apache.maven.project.MavenProject} * @throws org.apache.maven.project.ProjectBuildingException * Error parsing the POM file. */ MavenProject artifactInfo2MavenProject(ArtifactInfo artifactInfo) throws ProjectBuildingException { VersionRange versionRange = VersionRange.createFromVersion(artifactInfo.version); Artifact parentArtifact = new DefaultArtifact(artifactInfo.groupId, artifactInfo.artifactId, versionRange, "compile", "pom", null, new DefaultArtifactHandler()); ProjectBuildingResult buildingResult = projectBuilder.build(parentArtifact, this.buildRequest); return buildingResult.getProject(); }
From source file:org.axway.grapes.maven.materials.stubs.AbstractProjectStub.java
public AbstractProjectStub() { File testDir = new File( PlexusTestCase.getBasedir() + "/src/test/resources/materials/" + getProjectPath() + "/"); MavenXpp3Reader pomReader = new MavenXpp3Reader(); Model model;/*from w w w. j ava 2s .c o m*/ try { File pomFile = new File(testDir, "pom.xml"); // TODO: Once plexus-utils has been bumped to 1.4.4, use ReaderFactory.newXmlReader() model = pomReader.read(new InputStreamReader(new FileInputStream(pomFile), "UTF-8")); setModel(model); } catch (Exception e) { throw new RuntimeException(e); } /* Setup project */ setGroupId(model.getGroupId()); setArtifactId(model.getArtifactId()); setVersion(model.getVersion()); setName(model.getName()); setUrl(model.getUrl()); setPackaging(model.getPackaging()); /* Setup artifact */ artifact = new DefaultArtifact(model.getGroupId(), model.getArtifactId(), model.getVersion(), Scope.COMPILE.toString(), "jar", null, new DefaultArtifactHandler()); /* Setup License */ license = new License(); license.setName("License One"); license.setDistribution("Grapes Corp."); license.setComments("Best license ever"); license.setUrl("htt://somewhere.com"); /* Setup build */ build = new Build(); Resource resource = new Resource(); build.setFinalName(model.getArtifactId()); build.setDirectory(getBasedir().getAbsolutePath() + "/target"); build.setSourceDirectory(testDir + "/src/main/java"); resource.setDirectory(testDir + "/src/main/resources"); build.setResources(Collections.singletonList(resource)); build.setOutputDirectory(getBasedir().getAbsolutePath() + "/target/classes"); build.setTestSourceDirectory(testDir + "/src/test/java"); resource = new Resource(); resource.setDirectory(testDir + "/src/test/resources"); build.setTestResources(Collections.singletonList(resource)); build.setTestOutputDirectory(getBasedir().getAbsolutePath() + "/target/test-classes"); }
From source file:org.axway.grapes.maven.resolver.ArtifactResolver.java
/** * Resolve a dependency artifact//from www .j a v a 2 s. co m * * @param project MavenProject * @param dependency dependency * @return Artifact */ public Artifact resolveArtifact(final MavenProject project, final Dependency dependency) throws MojoExecutionException { // Manage version ranges String version = dependency.getVersion(); try { if (!version.matches("[0-9.]*")) { final VersionRange range = VersionRange.createFromVersionSpec(version); version = getArtifactVersion(range); } } catch (InvalidVersionSpecificationException e) { throw new MojoExecutionException("Failed to handle version range of " + dependency.toString(), e); } final DefaultArtifactHandler handler = new DefaultArtifactHandler(); handler.setExtension(dependency.getType()); final Artifact artifact = new DefaultArtifact(dependency.getGroupId(), dependency.getArtifactId(), version, null, dependency.getType(), dependency.getClassifier(), handler); resolveArtifact(project, artifact); return artifact; }
From source file:org.axway.grapes.maven.resolver.LicenseResolver.java
License:Open Source License
/** * Generate an model Artifact//from w ww . jav a2s .co m * * @param groupId String * @param artifactId String * @param version String * @return Artifact */ private Artifact getModelArtifact(final String groupId, final String artifactId, final String version) { final DefaultArtifactHandler handler = new DefaultArtifactHandler(); handler.setExtension("pom"); final Artifact model = new DefaultArtifact(groupId, artifactId, version, null, "pom", null, handler); return model; }
From source file:org.codehaus.mojo.cobertura.stubs.ArtifactStub.java
License:Apache License
public ArtifactHandler getArtifactHandler() { return new DefaultArtifactHandler() { public String getLanguage() { return "java"; }//ww w . ja v a 2 s.c o m }; }
From source file:org.codehaus.mojo.versions.UseLatestReleasesMojo.java
License:Apache License
private ArtifactVersion[] filterVersionsWithIncludes(ArtifactVersion[] newer, Artifact artifact) { List filteredNewer = new ArrayList(newer.length); for (int j = 0; j < newer.length; j++) { ArtifactVersion artifactVersion = newer[j]; Artifact artefactWithNewVersion = new DefaultArtifact(artifact.getGroupId(), artifact.getArtifactId(), VersionRange.createFromVersion(artifactVersion.toString()), artifact.getScope(), artifact.getType(), null, new DefaultArtifactHandler(), false); if (isIncluded(artefactWithNewVersion)) { filteredNewer.add(artifactVersion); }/*from ww w. j a va 2 s . c om*/ } return (ArtifactVersion[]) filteredNewer.toArray(new ArtifactVersion[filteredNewer.size()]); }
From source file:org.kie.workbench.common.services.backend.compiler.impl.utils.MavenUtils.java
License:Apache License
private static void createArtifacts(List<Dependency> pomDeps, Set<Artifact> deps) { if (pomDeps != null && pomDeps.size() > 0) { for (Dependency dep : pomDeps) { Artifact artifact = new DefaultArtifact(dep.getGroupId(), dep.getArtifactId(), dep.getVersion(), dep.getScope(), dep.getType(), dep.getClassifier(), new DefaultArtifactHandler()); deps.add(artifact);//from w w w . ja v a2s.c o m } } }