本文整理匯總了Java中org.apache.maven.artifact.DefaultArtifact類的典型用法代碼示例。如果您正苦於以下問題:Java DefaultArtifact類的具體用法?Java DefaultArtifact怎麽用?Java DefaultArtifact使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
DefaultArtifact類屬於org.apache.maven.artifact包,在下文中一共展示了DefaultArtifact類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: testMissingParent
import org.apache.maven.artifact.DefaultArtifact; //導入依賴的package包/類
public void testMissingParent() throws Exception {
TestFileUtils.writeFile(new File(getWorkDir(), "pom.xml"), "<project xmlns='http://maven.apache.org/POM/4.0.0'><modelVersion>4.0.0</modelVersion>" +
"<parent><groupId>g</groupId><artifactId>par</artifactId><version>0</version></parent>" +
"<artifactId>m</artifactId>" +
"</project>");
Project p = ProjectManager.getDefault().findProject(FileUtil.toFileObject(getWorkDir()));
assertEquals("g:m:jar:0", p.getLookup().lookup(NbMavenProject.class).getMavenProject().getId());
ProblemReporterImpl pr = getReporter(p);
MavenModelProblemsProvider mpp = new MavenModelProblemsProvider(p);
Collection<? extends ProjectProblemsProvider.ProjectProblem> problems = mpp.getProblems();
waitForReports();
assertFalse(problems.isEmpty());
assertEquals(Collections.singleton(a2f(new DefaultArtifact("g", "par", "0", null, "pom", null, new DefaultArtifactHandler("pom")))), pr.getMissingArtifactFiles());
}
示例2: setUp
import org.apache.maven.artifact.DefaultArtifact; //導入依賴的package包/類
protected void setUp()
throws Exception
{
super.setUp();
ArtifactHandler ah = new DefaultArtifactHandlerStub( "jar", null );
VersionRange vr = VersionRange.createFromVersion( "1.1" );
release = new DefaultArtifact( "test", "one", vr, Artifact.SCOPE_COMPILE, "jar", "sources", ah, false );
artifacts.add( release );
ah = new DefaultArtifactHandlerStub( "war", null );
vr = VersionRange.createFromVersion( "1.1-SNAPSHOT" );
snap = new DefaultArtifact( "test", "two", vr, Artifact.SCOPE_PROVIDED, "war", null, ah, false );
artifacts.add( snap );
ah = new DefaultArtifactHandlerStub( "war", null );
vr = VersionRange.createFromVersion( "1.1-SNAPSHOT" );
sources = new DefaultArtifact( "test", "two", vr, Artifact.SCOPE_PROVIDED, "sources", "sources", ah, false );
// pick random output location
Random a = new Random();
outputFolder = new File( "target/copy" + a.nextLong() + "/" );
outputFolder.delete();
assertFalse( outputFolder.exists() );
}
示例3: includeDependencies
import org.apache.maven.artifact.DefaultArtifact; //導入依賴的package包/類
protected void includeDependencies() {
Stream<Artifact> artifacts;
if (Boolean.TRUE.equals(listAllArtifacts)) {
artifacts = project.getArtifacts().stream()
.filter(artifact -> StringUtils.equals(artifact.getScope(), DefaultArtifact.SCOPE_PROVIDED));
} else {
artifacts = this.project.getDependencies().stream()
.filter(dependency -> StringUtils.equals(dependency.getScope(), DefaultArtifact.SCOPE_PROVIDED))
.map(this::toArtifact);
}
artifacts.map(Artifact::getId)
.sorted()
.map(io.syndesis.model.Dependency::maven)
.forEachOrdered(extensionBuilder::addDependency);
}
示例4: isArtifactAvailableLocally
import org.apache.maven.artifact.DefaultArtifact; //導入依賴的package包/類
/**
* Checks if an artifact is available in the local repository. The artifact <code>version</code>
* must be a specific value, cannot be "LATEST".
*/
public static boolean isArtifactAvailableLocally(String groupId, String artifactId,
String version, String type,
String classifier) {
try {
Preconditions.checkArgument(!MAVEN_LATEST_VERSION.equals(version));
String artifactPath =
MavenPlugin.getMaven().getLocalRepository()
.pathOf(new DefaultArtifact(groupId, artifactId, version, null /* scope */, type,
classifier, new DefaultArtifactHandler(type)));
return new File(artifactPath).exists();
} catch (CoreException ex) {
logger.log(Level.SEVERE, "Could not lookup local repository", ex);
return false;
}
}
示例5: setupArtifact
import org.apache.maven.artifact.DefaultArtifact; //導入依賴的package包/類
@SuppressWarnings( "unchecked" )
void setupArtifact( String groupId, String artifactId, String goal, String type )
throws DuplicateMojoDescriptorException, PluginNotFoundException, PluginResolutionException, PluginDescriptorParsingException, InvalidPluginDescriptorException {
DefaultArtifact artifact = new DefaultArtifact( groupId, artifactId, "DUMMY", "compile", type, "", null );
MojoDescriptor mojoDescriptor = new MojoDescriptor();
mojoDescriptor.setGoal( goal );
PluginDescriptor pluginDescriptor = new PluginDescriptor();
pluginDescriptor.addMojo( mojoDescriptor );
Plugin plugin = new Plugin();
plugin.setGroupId( groupId );
plugin.setArtifactId( artifactId );
when( this.mojo.pluginManager.loadPlugin( eq( plugin ), anyList(), any( RepositorySystemSession.class ) ) ).thenReturn( pluginDescriptor );
this.mojo.pluginDescriptor.getArtifactMap().put( String.format( "%s:%s", groupId, artifactId ), artifact );
}
示例6: retrieveAvailableVersions
import org.apache.maven.artifact.DefaultArtifact; //導入依賴的package包/類
@NotNull
@Override
public List<String> retrieveAvailableVersions(@NotNull String groupId,
@NotNull String artifactId,
@NotNull List<MavenRemoteRepository> remoteRepositories)
throws RemoteException {
try {
Artifact artifact =
new DefaultArtifact(groupId, artifactId, "", Artifact.SCOPE_COMPILE, "pom", null, new DefaultArtifactHandler("pom"));
List<ArtifactVersion> versions = getComponent(ArtifactMetadataSource.class)
.retrieveAvailableVersions(
artifact,
getLocalRepository(),
convertRepositories(remoteRepositories));
return ContainerUtil.map(versions, new Function<ArtifactVersion, String>() {
@Override
public String fun(ArtifactVersion version) {
return version.toString();
}
});
}
catch (Exception e) {
Maven3ServerGlobals.getLogger().info(e);
}
return Collections.emptyList();
}
示例7: extractArtifact
import org.apache.maven.artifact.DefaultArtifact; //導入依賴的package包/類
/**
* This returns a {@link DefaultArtifact} object with the same groupId,
* artifactId, version and scope as the main artifact of the project
* (for instance 'bw-ear' or 'projlib').
*
* This {@link DefaultArtifact} will have its own {@link type} and
* {@link classifier}.
*
* @param a
* @param type
* @param classifier
* @return
*/
private Artifact extractArtifact(Artifact a, String type, String classifier) {
if (a == null) {
return a;
}
Artifact result = new DefaultArtifact(a.getGroupId(),
a.getArtifactId(),
a.getVersionRange(),
a.getScope(),
type,
classifier,
new DefaultArtifactHandler(type));
return result;
}
示例8: testMojoLookup
import org.apache.maven.artifact.DefaultArtifact; //導入依賴的package包/類
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();
}
示例9: testMojoLookup
import org.apache.maven.artifact.DefaultArtifact; //導入依賴的package包/類
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() );
}
示例10: filterVersionsWithIncludes
import org.apache.maven.artifact.DefaultArtifact; //導入依賴的package包/類
private ArtifactVersion[] filterVersionsWithIncludes( ArtifactVersion[] newer, Artifact artifact )
{
List<ArtifactVersion> 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 );
}
}
return filteredNewer.toArray( new ArtifactVersion[filteredNewer.size()] );
}
示例11: testFindArtifactInRepository
import org.apache.maven.artifact.DefaultArtifact; //導入依賴的package包/類
@Test
public void testFindArtifactInRepository() throws MojoExecutionException {
GenerateMojo mojo = new GenerateMojo();
mojo.setLog(new SystemStreamLog());
Dependency dependency = mojo.findArtifactInRepository(
new DefaultArtifact("org.spigotmc", "spigot-api", "1.8-R0.1-SNAPSHOT",
"compile", "jar", "jar", new DefaultArtifactHandler()),
new MavenArtifactRepository("yawkat",
"http://mvn.yawk.at",
new DefaultRepositoryLayout(),
new ArtifactRepositoryPolicy(),
new ArtifactRepositoryPolicy())
);
Assert.assertNotNull(dependency);
}
示例12: getDependencies
import org.apache.maven.artifact.DefaultArtifact; //導入依賴的package包/類
/**
* Collects dependencies, including transitives.
* Project dependencies retain their scope, while test only dependencies (including transitives) will have test scope.
* @param projectDependencies
* @return
*/
private Set<Artifact> getDependencies(final Set<Artifact> projectDependencies) {
Set<Artifact> result = new LinkedHashSet<Artifact>(projectDependencies);
Set<Artifact> testDependencies = dependenciesWithScope(projectDependencies, Artifact.SCOPE_TEST);
Set<Artifact> nonTestDependencies = allBut(projectDependencies, testDependencies);
Set<Artifact> testTransitives = resolve(testDependencies);
Set<Artifact> nonTestTransitives = resolve(nonTestDependencies);
Set<Artifact> testOnlyDependencies = allBut(testTransitives, nonTestTransitives);
for (Artifact testOnly : testOnlyDependencies) {
result.add(new DefaultArtifact(testOnly.getGroupId(), testOnly.getArtifactId(), testOnly.getVersion(), Artifact.SCOPE_TEST, testOnly.getType(), testOnly.getClassifier(), testOnly
.getArtifactHandler()));
}
result.addAll(resolve(projectDependencies));
return result;
}
示例13: resolveDependencies
import org.apache.maven.artifact.DefaultArtifact; //導入依賴的package包/類
private Map<Artifact, Dependency> resolveDependencies(BomImport bom) throws Exception {
org.eclipse.aether.artifact.Artifact artifact = new org.eclipse.aether.artifact.DefaultArtifact(bom.getGroupId(), bom.getArtifactId(), "pom", bom.getVersion());
List<RemoteRepository> repositories = remoteRepositories;
if (bom.getRepository() != null) {
// Include the additional repository into the copy
repositories = new LinkedList<RemoteRepository>(repositories);
RemoteRepository repo = new RemoteRepository.Builder(bom.getArtifactId() + "-repository", "default", bom.getRepository()).build();
repositories.add(0, repo);
}
ArtifactRequest artifactRequest = new ArtifactRequest(artifact, repositories, null);
system.resolveArtifact(session, artifactRequest); // To get an error when the artifact does not exist
ArtifactDescriptorRequest req = new ArtifactDescriptorRequest(artifact, repositories, null);
ArtifactDescriptorResult res = system.readArtifactDescriptor(session, req);
Map<Artifact, Dependency> mavenDependencies = new LinkedHashMap<Artifact, Dependency>();
if (res.getManagedDependencies() != null) {
for (org.eclipse.aether.graph.Dependency dep : res.getManagedDependencies()) {
mavenDependencies.put(toMavenArtifact(dep), toMavenDependency(dep));
}
}
return mavenDependencies;
}
示例14: testExcludeArtifacts
import org.apache.maven.artifact.DefaultArtifact; //導入依賴的package包/類
@Test
public void testExcludeArtifacts() throws Exception {
final CheckMojo mojo = getMojo("exclude-dependencies");
// inject some dependencies to exclude later
mojo.project.setArtifacts(ImmutableSet.of(
new DefaultArtifact("com.foobar", "bizbat", "1.2.3", "compile", "jar", "", null)
));
mojo.execute();
ArgumentCaptor<ImmutableList> toCheck = ArgumentCaptor.forClass(ImmutableList.class);
verify(conflictChecker).check(
any(Artifact.class),
toCheck.capture(),
anyListOf(Artifact.class)
);
assertThat(toCheck.getValue()).isEmpty();
}
示例15: filterVersionsWithIncludes
import org.apache.maven.artifact.DefaultArtifact; //導入依賴的package包/類
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 );
}
}
return (ArtifactVersion[]) filteredNewer.toArray( new ArtifactVersion[filteredNewer.size()] );
}