origins.put(fileExtension, new FileInputStream(origin));
}
public void installArchetype() throws CoreException {
try {
IMaven maven = MavenPlugin.getMaven();
// first get the plexus container
PlexusContainer container = ((MavenImpl) MavenPlugin.getMaven()).getPlexusContainer();
// then get the DefaultMaven
DefaultMaven mvn = (DefaultMaven) container.lookup(Maven.class);
// now create a RepositorySystemSession
MavenExecutionRequest request = new DefaultMavenExecutionRequest();
request.setLocalRepository(maven.getLocalRepository());
// We need to support Maven 3.0.x as well, so we use reflection to
// access Aether APIs in a manner which is compatible with all Maven 3.x versions
// See https://maven.apache.org/docs/3.1.0/release-notes.html
MavenSession session = reflectiveCreateMavenSession(container, mvn, request);
LegacySupport legacy = container.lookup(LegacySupport.class);
legacy.setSession(session);
// then lookup the DefaultArtifactInstaller
DefaultArtifactInstaller dai = (DefaultArtifactInstaller) container.lookup(ArtifactInstaller.class);
final Set<Entry<String, InputStream>> entries = origins.entrySet();
for (Iterator<Entry<String, InputStream>> it = entries.iterator(); it.hasNext();) {
final Entry<String, InputStream> entry = it.next();
final String fileExtension = entry.getKey();
final InputStream in = entry.getValue();
File tmpFile = File.createTempFile("slingClipseTmp", fileExtension);
FileOutputStream fos = new FileOutputStream(tmpFile);
try {
IOUtils.copy(in, fos);
Artifact jarArtifact = new DefaultArtifact(groupId, artifactId, version, "", fileExtension, "",
new DefaultArtifactHandler());
dai.install(tmpFile, jarArtifact, maven.getLocalRepository());
} finally {
IOUtils.closeQuietly(in);
IOUtils.closeQuietly(fos);
FileUtils.deleteQuietly(tmpFile);
}