Hi

I want to install a file into my local repository. The code below did work at 
one time but now it is creating the file in the local repository but that file 
is empty. Any idea on how to fix it or is there another way to do that?

Current Maven version:

mvn --version
Apache Maven 3.6.3 (cecedd343002696d0abb50b32b541b8a6ba2883f)
Maven home: /Java/maven3
Java version: 1.8.0_201, vendor: Oracle Corporation, runtime: 
/Library/Java/JavaVirtualMachines/jdk1.8.0_201.jdk/Contents/Home/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "mac os x", version: "10.14.6", arch: "x86_64", family: “mac"

Requirements:

This code is installing a generated file (JSon file) into the local repository 
with the extension ’slingosgifeature’. The packaging is ‘jar’ as this project 
creates a JAR file. That said it needs also to install that file into the local 
repository.

Code:

private void installFMDescriptor(File file, Feature feature) {
    Collection<org.apache.maven.artifact.Artifact> artifacts = 
Collections.synchronizedCollection(new ArrayList<>());
    if(file.exists() && file.canRead()) {
        getLog().debug("FM File to be installed: " + file.getAbsolutePath());
        // Need to create a new Artifact Handler for the different extension 
and an Artifact to not
        // change the module artifact
        DefaultArtifactHandler fmArtifactHandler = new 
DefaultArtifactHandler("slingosgifeature");
        ArtifactId artifactId = feature.getId();
        DefaultArtifact fmArtifact = new DefaultArtifact(
            artifactId.getGroupId(), artifactId.getArtifactId(), 
artifactId.getVersion(),
            null, "slingosgifeature", null, fmArtifactHandler
        );
        fmArtifact.setFile(file);
        artifacts.add(fmArtifact);
        try {
            installArtifact(mavenSession.getProjectBuildingRequest(), 
artifacts);
        } catch (MojoExecutionException e) {
            getLog().error("Failed to install FM Descriptor", e);
        }
    } else {
        getLog().error("Could not find FM Descriptor File: " + file);
    }
}

private void installArtifact(ProjectBuildingRequest pbr, 
Collection<org.apache.maven.artifact.Artifact> artifacts )
    throws MojoExecutionException {
    try {
        installer.install(pbr, artifacts);
    } catch ( ArtifactInstallerException e ) {
        throw new MojoExecutionException( "ArtifactInstallerException", e );
    }
}

Cheers - Andy Schaefer
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@maven.apache.org
For additional commands, e-mail: users-h...@maven.apache.org

Reply via email to