Java Code Examples for org.apache.maven.artifact.DefaultArtifact#setFile()

The following examples show how to use org.apache.maven.artifact.DefaultArtifact#setFile() . 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: ShrinkWrapFatJarPackageServiceTest.java    From vertx-maven-plugin with Apache License 2.0 5 votes vote down vote up
@Test
public void testEmbeddingDependenciesWithAMissingArtifactFile() throws IOException, PackagingException {
    AbstractVertxMojo mojo = mock(AbstractVertxMojo.class);
    when(mojo.getLog()).thenReturn(new SystemStreamLog());

    Archive archive = new Archive();
    archive.setIncludeClasses(false);
    archive.setDependencySets(ImmutableList.of(new DependencySet()));

    DefaultArtifact artifact = getSecondArtifact();
    artifact.setFile(new File("missing-on-purpose"));
    Set<Artifact> artifacts = ImmutableSet.of(getFirstArtifact(), artifact);

    File output = new File(out, "test-all-dependencies-missing-artifact-file.jar");
    PackageConfig config = new PackageConfig()
        .setMojo(mojo)
        .setOutput(output)
        .setArtifacts(artifacts)
        .setArchive(archive);
    service.doPackage(config);

    assertThat(output).isFile();
    JarFile jar = new JarFile(output);
    List<String> list = jar.stream().map(ZipEntry::getName)
        .filter(s -> ! s.endsWith("/")) // Directories
        .collect(Collectors.toList());
    assertThat(list).containsOnly("META-INF/MANIFEST.MF", "testconfig.yaml");
}
 
Example 2
Source File: ShrinkWrapFatJarPackageServiceTest.java    From vertx-maven-plugin with Apache License 2.0 5 votes vote down vote up
private DefaultArtifact getFirstArtifact() {
    JavaArchive jarArchive1 = ShrinkWrap.create(JavaArchive.class);
    jarArchive1.addAsResource(new File("src/test/resources/testconfig.yaml"));
    File jar1 = new File(out, "jar1.jar");
    jarArchive1.as(ZipExporter.class).exportTo(jar1, true);

    DefaultArtifact artifact = new DefaultArtifact("org.acme", "jar1", "1.0", "compile", "jar", "", null);
    artifact.setFile(jar1);
    return artifact;
}
 
Example 3
Source File: ShrinkWrapFatJarPackageServiceTest.java    From vertx-maven-plugin with Apache License 2.0 5 votes vote down vote up
private DefaultArtifact getSecondArtifact() {
    JavaArchive archive = ShrinkWrap.create(JavaArchive.class);
    archive.addAsResource(new File("src/test/resources/testconfig2.yaml"), "out/some-config.yaml");
    File jar = new File(out, "jar2.jar");
    archive.as(ZipExporter.class).exportTo(jar, true);

    DefaultArtifact artifact = new DefaultArtifact("org.acme", "jar2", "1.0", "compile", "jar", "", null);
    artifact.setFile(jar);
    return artifact;
}
 
Example 4
Source File: GeneratorTest.java    From webstart with MIT License 5 votes vote down vote up
@Override
public void setUp()
    throws Exception
{
    super.setUp();
    DefaultArtifactHandler artifactHandler = new DefaultArtifactHandler( "jar" );
    artifact1 =
        new DefaultArtifact( "groupId", "artifact1", VersionRange.createFromVersion( "1.0" ), "scope", "jar",
                             "classifier", artifactHandler );
    artifact1.setFile( new File( "artifact1-1.0.jar" ) );
    artifact2 =
        new DefaultArtifact( "groupId", "artifact2", VersionRange.createFromVersion( "1.5" ), null, "jar", "",
                             artifactHandler );
    artifact2.setFile( new File( "artifact2-1.5.jar" ) );

    // add a SNAPSHOT artifact, timestamped (from a remote maven repository)
    artifact3 =
            new DefaultArtifact( "groupId", "artifact3", VersionRange.createFromVersion( "1.5-SNAPSHOT" ), null, "jar", "",
                                 artifactHandler );
    artifact3.setVersion("1.5-15012014.121212-1");
    artifact3.setFile( new File( "artifact3-1.5-15012014.121212-1.jar" ) );

    // add a SNAPSHOT artifact, not timestamped (from a local build)
    artifact4 =
            new DefaultArtifact( "groupId", "artifact4", VersionRange.createFromVersion( "1.5-SNAPSHOT" ), null, "jar", "",
                                 artifactHandler );
    artifact4.setFile( new File( "artifact4-1.5-SNAPSHOT.jar" ) );

    artifacts = new ArrayList<>();

    artifacts.add( artifact1 );
    artifacts.add( artifact2 );
    artifacts.add( artifact3 );
    artifacts.add( artifact4 );
}
 
Example 5
Source File: TestPropertiesMojoTest.java    From takari-lifecycle with Eclipse Public License 1.0 5 votes vote down vote up
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 6
Source File: DependencyEmbedderTest.java    From wisdom with Apache License 2.0 5 votes vote down vote up
private Artifact create(String g, String a, String v) {
    DefaultArtifact artifact = new MavenArtifact();
    artifact.setGroupId(g);
    artifact.setArtifactId(a);
    artifact.setVersion(v);
    artifact.setFile(new File("target/junk/" + a + "-" + v + ".jar"));
    return artifact;
}
 
Example 7
Source File: NativeLinkMojo.java    From maven-native with MIT License 4 votes vote down vote up
/**
 *
 */
private void attachPrimaryArtifact()
{
    Artifact artifact = this.project.getArtifact();

    if ( null == this.classifier )
    {
        artifact.setFile( new File( this.linkerOutputDirectory + "/" + this.project.getBuild().getFinalName() + "."
                + this.project.getArtifact().getArtifactHandler().getExtension() ) );
    }
    else
    {
        // install primary artifact as a classifier

        DefaultArtifact clone = new DefaultArtifact( artifact.getGroupId(), artifact.getArtifactId(),
                artifact.getVersionRange().cloneOf(), artifact.getScope(), artifact.getType(), classifier,
                artifact.getArtifactHandler(), artifact.isOptional() );

        clone.setRelease( artifact.isRelease() );
        clone.setResolvedVersion( artifact.getVersion() );
        clone.setResolved( artifact.isResolved() );
        clone.setFile( artifact.getFile() );

        if ( artifact.getAvailableVersions() != null )
        {
            clone.setAvailableVersions( new ArrayList<>( artifact.getAvailableVersions() ) );
        }

        clone.setBaseVersion( artifact.getBaseVersion() );
        clone.setDependencyFilter( artifact.getDependencyFilter() );

        if ( artifact.getDependencyTrail() != null )
        {
            clone.setDependencyTrail( new ArrayList<>( artifact.getDependencyTrail() ) );
        }

        clone.setDownloadUrl( artifact.getDownloadUrl() );
        clone.setRepository( artifact.getRepository() );

        clone.setFile( new File( this.linkerOutputDirectory + "/" + this.project.getBuild().getFinalName() + "."
                + this.project.getArtifact().getArtifactHandler().getExtension() ) );

        project.setArtifact( clone );
    }
}
 
Example 8
Source File: AbstractSundrioMojo.java    From sundrio with Apache License 2.0 4 votes vote down vote up
Artifact createArtifact(File file, String groupId, String artifactId, String version, String scope, String type, String classifier) {
    DefaultArtifact artifact = new DefaultArtifact(groupId, artifactId, version, scope, type, classifier, artifactHandler);
    artifact.setFile(file);
    artifact.setResolved(true);
    return artifact;
}
 
Example 9
Source File: CassandraServer.java    From geowave with Apache License 2.0 4 votes vote down vote up
private StartGeoWaveCluster(final int numNodes, final int memory, final String directory) {
  super();
  startWaitSeconds = 180;
  rpcAddress = "127.0.0.1";
  rpcPort = 9160;
  jmxPort = 7199;
  startNativeTransport = true;
  nativeTransportPort = 9042;
  listenAddress = "127.0.0.1";
  storagePort = 7000;
  stopPort = 8081;
  stopKey = "cassandra-maven-plugin";
  maxMemory = memory;
  cassandraDir = new File(directory, NODE_DIRECTORY_PREFIX);
  logLevel = "ERROR";
  project = new MavenProject();
  project.setFile(cassandraDir);
  Field f;
  try {
    f = StartCassandraClusterMojo.class.getDeclaredField("clusterSize");
    f.setAccessible(true);
    f.set(this, numNodes);
    f = AbstractCassandraMojo.class.getDeclaredField("pluginArtifact");

    f.setAccessible(true);
    final DefaultArtifact a =
        new DefaultArtifact(
            "group",
            "artifact",
            VersionRange.createFromVersionSpec("version"),
            null,
            "type",
            null,
            new DefaultArtifactHandler());
    a.setFile(cassandraDir);
    f.set(this, a);

    f = AbstractCassandraMojo.class.getDeclaredField("pluginDependencies");
    f.setAccessible(true);
    f.set(this, new ArrayList<>());
  } catch (NoSuchFieldException | SecurityException | IllegalArgumentException
      | IllegalAccessException | InvalidVersionSpecificationException e) {
    LOGGER.error("Unable to initialize start cassandra cluster", e);
  }
}
 
Example 10
Source File: CassandraServer.java    From geowave with Apache License 2.0 4 votes vote down vote up
private StartGeoWaveStandalone(final int memory, final String directory) {
  super();
  startWaitSeconds = 180;
  rpcAddress = "127.0.0.1";
  rpcPort = 9160;
  jmxPort = 7199;
  startNativeTransport = true;
  nativeTransportPort = 9042;
  listenAddress = "127.0.0.1";
  storagePort = 7000;
  stopPort = 8081;
  stopKey = "cassandra-maven-plugin";
  maxMemory = memory;
  cassandraDir = new File(directory);
  logLevel = "ERROR";
  project = new MavenProject();
  project.setFile(cassandraDir);
  Field f;
  try {
    f = AbstractCassandraMojo.class.getDeclaredField("pluginArtifact");

    f.setAccessible(true);
    final DefaultArtifact a =
        new DefaultArtifact(
            "group",
            "artifact",
            VersionRange.createFromVersionSpec("version"),
            null,
            "type",
            null,
            new DefaultArtifactHandler());
    a.setFile(cassandraDir);
    f.set(this, a);

    f = AbstractCassandraMojo.class.getDeclaredField("pluginDependencies");
    f.setAccessible(true);
    f.set(this, new ArrayList<>());
  } catch (NoSuchFieldException | SecurityException | IllegalArgumentException
      | IllegalAccessException | InvalidVersionSpecificationException e) {
    LOGGER.error("Unable to initialize start cassandra cluster", e);
  }
}