Create spring-loader-tools project
Create spring-loader-tools containing utilities that can be used with both Maven and Gradle plugings. Refactored existing Maven plugin to use the new project. Issue: #53129653
This commit is contained in:
@@ -16,7 +16,7 @@
|
||||
<!-- Compile -->
|
||||
<dependency>
|
||||
<groupId>${project.groupId}</groupId>
|
||||
<artifactId>spring-boot-loader</artifactId>
|
||||
<artifactId>spring-boot-loader-tools</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
|
||||
@@ -1,117 +0,0 @@
|
||||
/*
|
||||
* Copyright 2012-2013 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.boot.maven;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.maven.archiver.MavenArchiveConfiguration;
|
||||
import org.apache.maven.plugin.AbstractMojo;
|
||||
import org.apache.maven.plugin.MojoExecutionException;
|
||||
import org.apache.maven.plugins.annotations.Parameter;
|
||||
import org.apache.maven.project.MavenProject;
|
||||
|
||||
/**
|
||||
* Abstract base class for MOJOs that work with executable archives.
|
||||
*
|
||||
* @author Phillip Webb
|
||||
*/
|
||||
public abstract class AbstractExecutableArchiveMojo extends AbstractMojo {
|
||||
|
||||
protected static final String MAIN_CLASS_ATTRIBUTE = "Main-Class";
|
||||
|
||||
private static final Map<String, ArchiveHelper> ARCHIVE_HELPERS;
|
||||
static {
|
||||
Map<String, ArchiveHelper> helpers = new HashMap<String, ArchiveHelper>();
|
||||
helpers.put("jar", new ExecutableJarHelper());
|
||||
helpers.put("war", new ExecutableWarHelper());
|
||||
ARCHIVE_HELPERS = Collections.unmodifiableMap(helpers);
|
||||
}
|
||||
|
||||
/**
|
||||
* The Maven project.
|
||||
*/
|
||||
@Parameter(defaultValue = "${project}", readonly = true, required = true)
|
||||
private MavenProject project;
|
||||
|
||||
/**
|
||||
* Directory containing the classes and resource files that should be packaged into
|
||||
* the archive.
|
||||
*/
|
||||
@Parameter(defaultValue = "${project.build.outputDirectory}", required = true)
|
||||
private File classesDirectrory;
|
||||
|
||||
/**
|
||||
* The name of the main class. If not specified the first compiled class found that
|
||||
* contains a 'main' method will be used.
|
||||
*/
|
||||
@Parameter
|
||||
private String mainClass;
|
||||
|
||||
/**
|
||||
* The archive configuration to use. See <a
|
||||
* href="http://maven.apache.org/shared/maven-archiver/index.html">Maven Archiver
|
||||
* Reference</a>.
|
||||
*/
|
||||
@Parameter
|
||||
private MavenArchiveConfiguration archive = new MavenArchiveConfiguration();
|
||||
|
||||
protected final ArchiveHelper getArchiveHelper() throws MojoExecutionException {
|
||||
ArchiveHelper helper = ARCHIVE_HELPERS.get(getType());
|
||||
if (helper == null) {
|
||||
throw new MojoExecutionException("Unsupported packaging type: " + getType());
|
||||
}
|
||||
return helper;
|
||||
}
|
||||
|
||||
protected final String getStartClass() throws MojoExecutionException {
|
||||
String mainClass = this.mainClass;
|
||||
if (mainClass == null) {
|
||||
mainClass = this.archive.getManifestEntries().get(MAIN_CLASS_ATTRIBUTE);
|
||||
}
|
||||
if (mainClass == null) {
|
||||
mainClass = MainClassFinder.findMainClass(this.classesDirectrory);
|
||||
}
|
||||
if (mainClass == null) {
|
||||
throw new MojoExecutionException("Unable to find a suitable main class, "
|
||||
+ "please add a 'mainClass' property");
|
||||
}
|
||||
return mainClass;
|
||||
}
|
||||
|
||||
protected final MavenProject getProject() {
|
||||
return this.project;
|
||||
}
|
||||
|
||||
protected final String getType() {
|
||||
return this.project.getPackaging();
|
||||
}
|
||||
|
||||
protected final String getExtension() {
|
||||
return getProject().getPackaging();
|
||||
}
|
||||
|
||||
protected final MavenArchiveConfiguration getArchiveConfiguration() {
|
||||
return this.archive;
|
||||
}
|
||||
|
||||
protected final File getClassesDirectory() {
|
||||
return this.classesDirectrory;
|
||||
}
|
||||
}
|
||||
@@ -1,40 +0,0 @@
|
||||
/*
|
||||
* Copyright 2012-2013 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.boot.maven;
|
||||
|
||||
import org.apache.maven.artifact.Artifact;
|
||||
|
||||
/**
|
||||
* Strategy interface used by {@link ExecutableArchiveMojo} when creating archives.
|
||||
*
|
||||
* @author Dave Syer
|
||||
*/
|
||||
public interface ArchiveHelper {
|
||||
|
||||
/**
|
||||
* Returns the destination of an {@link Artifact}.
|
||||
* @param artifact the artifact
|
||||
* @return the destination or {@code null} to exclude
|
||||
*/
|
||||
String getArtifactDestination(Artifact artifact);
|
||||
|
||||
/**
|
||||
* Returns the launcher class that will be used.
|
||||
*/
|
||||
String getLauncherClass();
|
||||
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* Copyright 2012-2013 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.boot.maven;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.maven.artifact.Artifact;
|
||||
import org.springframework.boot.launcher.tools.Libraries;
|
||||
import org.springframework.boot.launcher.tools.LibraryCallback;
|
||||
import org.springframework.boot.launcher.tools.LibraryScope;
|
||||
|
||||
/**
|
||||
* {@link Libraries} backed by Maven {@link Artifact}s
|
||||
*
|
||||
* @author Phillip Webb
|
||||
*/
|
||||
public class ArtifactsLibraries implements Libraries {
|
||||
|
||||
private static final Map<String, LibraryScope> SCOPES;
|
||||
static {
|
||||
Map<String, LibraryScope> scopes = new HashMap<String, LibraryScope>();
|
||||
scopes.put(Artifact.SCOPE_COMPILE, LibraryScope.COMPILE);
|
||||
scopes.put(Artifact.SCOPE_RUNTIME, LibraryScope.RUNTIME);
|
||||
scopes.put(Artifact.SCOPE_PROVIDED, LibraryScope.PROVIDED);
|
||||
SCOPES = Collections.unmodifiableMap(scopes);
|
||||
}
|
||||
|
||||
private final Set<Artifact> artifacts;
|
||||
|
||||
public ArtifactsLibraries(Set<Artifact> artifacts) {
|
||||
this.artifacts = artifacts;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doWithLibraries(LibraryCallback callback) throws IOException {
|
||||
for (Artifact artifact : this.artifacts) {
|
||||
LibraryScope scope = SCOPES.get(artifact.getScope());
|
||||
if (scope != null && artifact.getFile() != null) {
|
||||
callback.library(artifact.getFile(), scope);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,289 +0,0 @@
|
||||
/*
|
||||
* Copyright 2012-2013 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.boot.maven;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Enumeration;
|
||||
import java.util.List;
|
||||
import java.util.jar.Attributes;
|
||||
import java.util.jar.Attributes.Name;
|
||||
|
||||
import org.apache.maven.archiver.MavenArchiver;
|
||||
import org.apache.maven.artifact.Artifact;
|
||||
import org.apache.maven.execution.MavenSession;
|
||||
import org.apache.maven.plugin.MojoExecutionException;
|
||||
import org.apache.maven.plugin.MojoFailureException;
|
||||
import org.apache.maven.plugins.annotations.Component;
|
||||
import org.apache.maven.plugins.annotations.LifecyclePhase;
|
||||
import org.apache.maven.plugins.annotations.Mojo;
|
||||
import org.apache.maven.plugins.annotations.Parameter;
|
||||
import org.apache.maven.plugins.annotations.ResolutionScope;
|
||||
import org.apache.maven.project.MavenProjectHelper;
|
||||
import org.codehaus.plexus.archiver.Archiver;
|
||||
import org.codehaus.plexus.archiver.jar.JarArchiver;
|
||||
import org.codehaus.plexus.archiver.jar.Manifest;
|
||||
import org.codehaus.plexus.archiver.zip.ZipEntry;
|
||||
import org.codehaus.plexus.archiver.zip.ZipFile;
|
||||
import org.codehaus.plexus.archiver.zip.ZipResource;
|
||||
import org.codehaus.plexus.util.IOUtil;
|
||||
import org.sonatype.aether.RepositorySystem;
|
||||
import org.sonatype.aether.RepositorySystemSession;
|
||||
import org.sonatype.aether.repository.RemoteRepository;
|
||||
import org.sonatype.aether.resolution.ArtifactDescriptorRequest;
|
||||
import org.sonatype.aether.resolution.ArtifactDescriptorResult;
|
||||
import org.sonatype.aether.resolution.ArtifactRequest;
|
||||
import org.sonatype.aether.resolution.ArtifactResult;
|
||||
import org.sonatype.aether.util.artifact.DefaultArtifact;
|
||||
|
||||
/**
|
||||
* MOJO that can can be used to repackage existing JAR and WAR archives so that they can
|
||||
* be executed from the command line using {@literal java -jar}.
|
||||
*
|
||||
* @author Phillip Webb
|
||||
* @author Dave Syer
|
||||
*/
|
||||
@Mojo(name = "package", defaultPhase = LifecyclePhase.PACKAGE, requiresProject = true, threadSafe = true, requiresDependencyResolution = ResolutionScope.COMPILE_PLUS_RUNTIME, requiresDependencyCollection = ResolutionScope.COMPILE_PLUS_RUNTIME)
|
||||
public class ExecutableArchiveMojo extends AbstractExecutableArchiveMojo {
|
||||
|
||||
private static final String START_CLASS_ATTRIBUTE = "Start-Class";
|
||||
|
||||
/**
|
||||
* Archiver used to create a JAR file.
|
||||
*/
|
||||
@Component(role = Archiver.class, hint = "jar")
|
||||
private JarArchiver jarArchiver;
|
||||
|
||||
/**
|
||||
* Maven project helper utils.
|
||||
*/
|
||||
@Component
|
||||
private MavenProjectHelper projectHelper;
|
||||
|
||||
/**
|
||||
* Aether repository system used to download artifacts.
|
||||
*/
|
||||
@Component
|
||||
private RepositorySystem repositorySystem;
|
||||
|
||||
/**
|
||||
* The Maven session.
|
||||
*/
|
||||
@Parameter(defaultValue = "${session}", readonly = true, required = true)
|
||||
private MavenSession session;
|
||||
|
||||
/**
|
||||
* Directory containing the generated archive.
|
||||
*/
|
||||
@Parameter(defaultValue = "${project.build.directory}", required = true)
|
||||
private File outputDirectory;
|
||||
|
||||
/**
|
||||
* Name of the generated archive.
|
||||
*/
|
||||
@Parameter(defaultValue = "${project.build.finalName}", required = true)
|
||||
private String finalName;
|
||||
|
||||
/**
|
||||
* Classifier to add to the artifact generated. If given, the artifact will be
|
||||
* attached. If this is not given, it will merely be written to the output directory
|
||||
* according to the finalName.
|
||||
*/
|
||||
@Parameter
|
||||
private String classifier;
|
||||
|
||||
/**
|
||||
* Whether creating the archive should be forced.
|
||||
*/
|
||||
@Parameter(property = "archive.forceCreation", defaultValue = "true")
|
||||
private boolean forceCreation;
|
||||
|
||||
/**
|
||||
* The current repository/network configuration of Maven.
|
||||
*/
|
||||
@Parameter(defaultValue = "${repositorySystemSession}", readonly = true)
|
||||
private RepositorySystemSession repositorySystemSession;
|
||||
|
||||
@Override
|
||||
public void execute() throws MojoExecutionException, MojoFailureException {
|
||||
File archiveFile = createArchive();
|
||||
if (this.classifier == null || this.classifier.isEmpty()) {
|
||||
getProject().getArtifact().setFile(archiveFile);
|
||||
}
|
||||
else {
|
||||
getLog().info(
|
||||
"Attaching archive: " + archiveFile + ", with classifier: "
|
||||
+ this.classifier);
|
||||
this.projectHelper.attachArtifact(getProject(), getType(), this.classifier,
|
||||
archiveFile);
|
||||
}
|
||||
}
|
||||
|
||||
private File createArchive() throws MojoExecutionException {
|
||||
File archiveFile = getTargetFile();
|
||||
MavenArchiver archiver = new MavenArchiver();
|
||||
|
||||
archiver.setArchiver(this.jarArchiver);
|
||||
archiver.setOutputFile(archiveFile);
|
||||
archiver.getArchiver().setRecompressAddedZips(false);
|
||||
|
||||
try {
|
||||
getLog().info("Modifying archive: " + archiveFile);
|
||||
Manifest manifest = copyContent(archiver, getProject().getArtifact()
|
||||
.getFile());
|
||||
customizeArchiveConfiguration(manifest);
|
||||
addLibs(archiver);
|
||||
ZipFile zipFile = addLauncherClasses(archiver);
|
||||
try {
|
||||
archiver.createArchive(this.session, getProject(),
|
||||
getArchiveConfiguration());
|
||||
return archiveFile;
|
||||
}
|
||||
finally {
|
||||
zipFile.close();
|
||||
}
|
||||
}
|
||||
catch (Exception ex) {
|
||||
throw new MojoExecutionException("Error assembling archive", ex);
|
||||
}
|
||||
}
|
||||
|
||||
private Manifest copyContent(MavenArchiver archiver, File file) throws IOException {
|
||||
|
||||
FileInputStream input = new FileInputStream(file);
|
||||
File original = new File(this.outputDirectory, "original.jar");
|
||||
FileOutputStream output = new FileOutputStream(original);
|
||||
IOUtil.copy(input, output, 2048);
|
||||
input.close();
|
||||
output.close();
|
||||
|
||||
Manifest manifest = new Manifest();
|
||||
ZipFile zipFile = new ZipFile(original);
|
||||
Enumeration<? extends ZipEntry> entries = zipFile.getEntries();
|
||||
while (entries.hasMoreElements()) {
|
||||
ZipEntry entry = entries.nextElement();
|
||||
if (!entry.isDirectory()) {
|
||||
ZipResource zipResource = new ZipResource(zipFile, entry);
|
||||
getLog().debug("Copying resource: " + entry.getName());
|
||||
if (!entry.getName().toUpperCase().equals("META-INF/MANIFEST.MF")) {
|
||||
archiver.getArchiver().addResource(zipResource, entry.getName(), -1);
|
||||
}
|
||||
else {
|
||||
getLog().info("Found existing manifest");
|
||||
manifest = new Manifest(zipResource.getContents());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return manifest;
|
||||
|
||||
}
|
||||
|
||||
private File getTargetFile() {
|
||||
String classifier = (this.classifier == null ? "" : this.classifier.trim());
|
||||
if (classifier.length() > 0 && !classifier.startsWith("-")) {
|
||||
classifier = "-" + classifier;
|
||||
}
|
||||
return new File(this.outputDirectory, this.finalName + classifier + "."
|
||||
+ getExtension());
|
||||
}
|
||||
|
||||
private void customizeArchiveConfiguration(Manifest manifest)
|
||||
throws MojoExecutionException {
|
||||
getArchiveConfiguration().setForced(this.forceCreation);
|
||||
|
||||
Attributes attributes = manifest.getMainAttributes();
|
||||
for (Object name : attributes.keySet()) {
|
||||
String value = attributes.getValue((Name) name);
|
||||
getLog().debug("Existing manifest entry: " + name + "=" + value);
|
||||
getArchiveConfiguration().addManifestEntry(name.toString(), value);
|
||||
}
|
||||
|
||||
String startClass = getStartClass();
|
||||
getArchiveConfiguration().addManifestEntry(MAIN_CLASS_ATTRIBUTE,
|
||||
getArchiveHelper().getLauncherClass());
|
||||
getArchiveConfiguration().addManifestEntry(START_CLASS_ATTRIBUTE, startClass);
|
||||
}
|
||||
|
||||
private void addLibs(MavenArchiver archiver) throws MojoExecutionException {
|
||||
getLog().info("Adding dependencies");
|
||||
ArchiveHelper archiveHelper = getArchiveHelper();
|
||||
for (Artifact artifact : getProject().getArtifacts()) {
|
||||
if (artifact.getFile() != null) {
|
||||
String dir = archiveHelper.getArtifactDestination(artifact);
|
||||
if (dir != null) {
|
||||
getLog().debug("Adding dependency: " + artifact);
|
||||
archiver.getArchiver().addFile(artifact.getFile(),
|
||||
dir + artifact.getFile().getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private ZipFile addLauncherClasses(MavenArchiver archiver)
|
||||
throws MojoExecutionException {
|
||||
getLog().info("Adding launcher classes");
|
||||
try {
|
||||
List<RemoteRepository> repositories = new ArrayList<RemoteRepository>();
|
||||
repositories.addAll(getProject().getRemotePluginRepositories());
|
||||
repositories.addAll(getProject().getRemoteProjectRepositories());
|
||||
|
||||
String version = getClass().getPackage().getImplementationVersion();
|
||||
DefaultArtifact artifact = new DefaultArtifact(
|
||||
"org.springframework.boot:spring-boot-loader:" + version);
|
||||
ArtifactDescriptorRequest descriptorRequest = new ArtifactDescriptorRequest(
|
||||
artifact, repositories, "plugin");
|
||||
ArtifactDescriptorResult descriptorResult = this.repositorySystem
|
||||
.readArtifactDescriptor(this.repositorySystemSession,
|
||||
descriptorRequest);
|
||||
|
||||
ArtifactRequest artifactRequest = new ArtifactRequest();
|
||||
artifactRequest.setRepositories(repositories);
|
||||
artifactRequest.setArtifact(descriptorResult.getArtifact());
|
||||
ArtifactResult artifactResult = this.repositorySystem.resolveArtifact(
|
||||
this.repositorySystemSession, artifactRequest);
|
||||
|
||||
if (artifactResult.getArtifact() == null) {
|
||||
throw new MojoExecutionException("Unable to resolve launcher classes");
|
||||
}
|
||||
return addLauncherClasses(archiver, artifactResult.getArtifact().getFile());
|
||||
}
|
||||
catch (Exception ex) {
|
||||
if (ex instanceof MojoExecutionException) {
|
||||
throw (MojoExecutionException) ex;
|
||||
}
|
||||
throw new MojoExecutionException("Unable to add launcher classes", ex);
|
||||
}
|
||||
}
|
||||
|
||||
private ZipFile addLauncherClasses(MavenArchiver archiver, File file)
|
||||
throws IOException {
|
||||
ZipFile zipFile = new ZipFile(file);
|
||||
Enumeration<? extends ZipEntry> entries = zipFile.getEntries();
|
||||
while (entries.hasMoreElements()) {
|
||||
ZipEntry entry = entries.nextElement();
|
||||
if (!entry.isDirectory() && !entry.getName().startsWith("/META-INF")) {
|
||||
ZipResource zipResource = new ZipResource(zipFile, entry);
|
||||
archiver.getArchiver().addResource(zipResource, entry.getName(), -1);
|
||||
}
|
||||
}
|
||||
return zipFile;
|
||||
}
|
||||
}
|
||||
@@ -1,48 +0,0 @@
|
||||
/*
|
||||
* Copyright 2012-2013 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.boot.maven;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.maven.artifact.Artifact;
|
||||
|
||||
/**
|
||||
* Help build an executable JAR file.
|
||||
*
|
||||
* @author Phillip Webb
|
||||
* @author Dave Syer
|
||||
*/
|
||||
public class ExecutableJarHelper implements ArchiveHelper {
|
||||
|
||||
private static final Set<String> LIB_SCOPES = new HashSet<String>(Arrays.asList(
|
||||
"compile", "runtime", "provided"));
|
||||
|
||||
@Override
|
||||
public String getArtifactDestination(Artifact artifact) {
|
||||
if (LIB_SCOPES.contains(artifact.getScope())) {
|
||||
return "lib/";
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getLauncherClass() {
|
||||
return "org.springframework.boot.loader.JarLauncher";
|
||||
}
|
||||
}
|
||||
@@ -1,51 +0,0 @@
|
||||
/*
|
||||
* Copyright 2012-2013 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.boot.maven;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.maven.artifact.Artifact;
|
||||
|
||||
/**
|
||||
* Build an executable WAR file.
|
||||
*
|
||||
* @author Phillip Webb
|
||||
* @author Dave Syer
|
||||
*/
|
||||
public class ExecutableWarHelper implements ArchiveHelper {
|
||||
|
||||
private static final Map<String, String> SCOPE_DESTINATIONS;
|
||||
static {
|
||||
Map<String, String> map = new HashMap<String, String>();
|
||||
map.put("compile", "WEB-INF/lib/");
|
||||
map.put("runtime", "WEB-INF/lib/");
|
||||
map.put("provided", "WEB-INF/lib-provided/");
|
||||
SCOPE_DESTINATIONS = Collections.unmodifiableMap(map);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getArtifactDestination(Artifact artifact) {
|
||||
return SCOPE_DESTINATIONS.get(artifact.getScope());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getLauncherClass() {
|
||||
return "org.springframework.boot.loader.WarLauncher";
|
||||
}
|
||||
}
|
||||
@@ -1,158 +0,0 @@
|
||||
/*
|
||||
* Copyright 2012-2013 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.boot.maven;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileFilter;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayDeque;
|
||||
import java.util.Arrays;
|
||||
import java.util.Comparator;
|
||||
import java.util.Deque;
|
||||
|
||||
import org.objectweb.asm.ClassReader;
|
||||
import org.objectweb.asm.ClassVisitor;
|
||||
import org.objectweb.asm.MethodVisitor;
|
||||
import org.objectweb.asm.Opcodes;
|
||||
import org.objectweb.asm.Type;
|
||||
|
||||
/**
|
||||
* Finds any class with a {@code public static main} method by performing a breadth first
|
||||
* directory search.
|
||||
*
|
||||
* @author Phillip Webb
|
||||
*/
|
||||
abstract class MainClassFinder {
|
||||
|
||||
private static final String DOT_CLASS = ".class";
|
||||
|
||||
private static final Type STRING_ARRAY_TYPE = Type.getType(String[].class);
|
||||
|
||||
private static final Type MAIN_METHOD_TYPE = Type.getMethodType(Type.VOID_TYPE,
|
||||
STRING_ARRAY_TYPE);
|
||||
|
||||
private static final String MAIN_METHOD_NAME = "main";
|
||||
|
||||
private static final FileFilter CLASS_FILE_FILTER = new FileFilter() {
|
||||
@Override
|
||||
public boolean accept(File file) {
|
||||
return (file.isFile() && file.getName().endsWith(DOT_CLASS));
|
||||
}
|
||||
};
|
||||
|
||||
private static final FileFilter PACKAGE_FOLDER_FILTER = new FileFilter() {
|
||||
@Override
|
||||
public boolean accept(File file) {
|
||||
return file.isDirectory() && !file.getName().startsWith(".");
|
||||
}
|
||||
};
|
||||
|
||||
public static String findMainClass(File root) {
|
||||
File mainClassFile = findMainClassFile(root);
|
||||
if (mainClassFile == null) {
|
||||
return null;
|
||||
}
|
||||
String mainClass = mainClassFile.getAbsolutePath().substring(
|
||||
root.getAbsolutePath().length() + 1);
|
||||
mainClass = mainClass.replace('/', '.');
|
||||
mainClass = mainClass.replace('\\', '.');
|
||||
mainClass = mainClass.substring(0, mainClass.length() - DOT_CLASS.length());
|
||||
return mainClass;
|
||||
}
|
||||
|
||||
public static File findMainClassFile(File root) {
|
||||
Deque<File> stack = new ArrayDeque<File>();
|
||||
stack.push(root);
|
||||
while (!stack.isEmpty()) {
|
||||
File file = stack.pop();
|
||||
if (isMainClassFile(file)) {
|
||||
return file;
|
||||
}
|
||||
if (file.isDirectory()) {
|
||||
pushAllSorted(stack, file.listFiles(PACKAGE_FOLDER_FILTER));
|
||||
pushAllSorted(stack, file.listFiles(CLASS_FILE_FILTER));
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static boolean isMainClassFile(File file) {
|
||||
try {
|
||||
InputStream inputStream = new BufferedInputStream(new FileInputStream(file));
|
||||
try {
|
||||
ClassReader classReader = new ClassReader(inputStream);
|
||||
MainMethodFinder mainMethodFinder = new MainMethodFinder();
|
||||
classReader.accept(mainMethodFinder, ClassReader.SKIP_CODE);
|
||||
return mainMethodFinder.isFound();
|
||||
}
|
||||
finally {
|
||||
inputStream.close();
|
||||
}
|
||||
}
|
||||
catch (IOException ex) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private static void pushAllSorted(Deque<File> stack, File[] files) {
|
||||
Arrays.sort(files, new Comparator<File>() {
|
||||
@Override
|
||||
public int compare(File o1, File o2) {
|
||||
return o1.getName().compareTo(o2.getName());
|
||||
}
|
||||
});
|
||||
for (File file : files) {
|
||||
stack.push(file);
|
||||
}
|
||||
}
|
||||
|
||||
private static class MainMethodFinder extends ClassVisitor {
|
||||
|
||||
private boolean found;
|
||||
|
||||
public MainMethodFinder() {
|
||||
super(Opcodes.ASM4);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MethodVisitor visitMethod(int access, String name, String desc,
|
||||
String signature, String[] exceptions) {
|
||||
if (isAccess(access, Opcodes.ACC_PUBLIC, Opcodes.ACC_STATIC)
|
||||
&& MAIN_METHOD_NAME.equals(name)
|
||||
&& MAIN_METHOD_TYPE.getDescriptor().equals(desc)) {
|
||||
this.found = true;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private boolean isAccess(int access, int... requiredOpsCodes) {
|
||||
for (int requiredOpsCode : requiredOpsCodes) {
|
||||
if ((access & requiredOpsCode) == 0) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean isFound() {
|
||||
return this.found;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,115 @@
|
||||
/*
|
||||
* Copyright 2012-2013 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.boot.maven;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import org.apache.maven.plugin.AbstractMojo;
|
||||
import org.apache.maven.plugin.MojoExecutionException;
|
||||
import org.apache.maven.plugin.MojoFailureException;
|
||||
import org.apache.maven.plugins.annotations.Component;
|
||||
import org.apache.maven.plugins.annotations.LifecyclePhase;
|
||||
import org.apache.maven.plugins.annotations.Mojo;
|
||||
import org.apache.maven.plugins.annotations.Parameter;
|
||||
import org.apache.maven.plugins.annotations.ResolutionScope;
|
||||
import org.apache.maven.project.MavenProject;
|
||||
import org.apache.maven.project.MavenProjectHelper;
|
||||
import org.springframework.boot.launcher.tools.Libraries;
|
||||
import org.springframework.boot.launcher.tools.Repackager;
|
||||
|
||||
/**
|
||||
* MOJO that can can be used to repackage existing JAR and WAR archives so that they can
|
||||
* be executed from the command line using {@literal java -jar}.
|
||||
*
|
||||
* @author Phillip Webb
|
||||
* @author Dave Syer
|
||||
*/
|
||||
@Mojo(name = "package", defaultPhase = LifecyclePhase.PACKAGE, requiresProject = true, threadSafe = true, requiresDependencyResolution = ResolutionScope.COMPILE_PLUS_RUNTIME, requiresDependencyCollection = ResolutionScope.COMPILE_PLUS_RUNTIME)
|
||||
public class PackageMojo extends AbstractMojo {
|
||||
|
||||
/**
|
||||
* The Maven project.
|
||||
*/
|
||||
@Parameter(defaultValue = "${project}", readonly = true, required = true)
|
||||
private MavenProject project;
|
||||
|
||||
/**
|
||||
* Maven project helper utils.
|
||||
*/
|
||||
@Component
|
||||
private MavenProjectHelper projectHelper;
|
||||
|
||||
/**
|
||||
* Directory containing the generated archive.
|
||||
*/
|
||||
@Parameter(defaultValue = "${project.build.directory}", required = true)
|
||||
private File outputDirectory;
|
||||
|
||||
/**
|
||||
* Name of the generated archive.
|
||||
*/
|
||||
@Parameter(defaultValue = "${project.build.finalName}", required = true)
|
||||
private String finalName;
|
||||
|
||||
/**
|
||||
* Classifier to add to the artifact generated. If given, the artifact will be
|
||||
* attached. If this is not given, it will merely be written to the output directory
|
||||
* according to the finalName.
|
||||
*/
|
||||
@Parameter
|
||||
private String classifier;
|
||||
|
||||
/**
|
||||
* The name of the main class. If not specified the first compiled class found that
|
||||
* contains a 'main' method will be used.
|
||||
*/
|
||||
@Parameter
|
||||
private String mainClass;
|
||||
|
||||
@Override
|
||||
public void execute() throws MojoExecutionException, MojoFailureException {
|
||||
File source = this.project.getArtifact().getFile();
|
||||
File target = getTargetFile();
|
||||
Repackager repackager = new Repackager(source);
|
||||
repackager.setMainClass(this.mainClass);
|
||||
Libraries libraries = new ArtifactsLibraries(this.project.getArtifacts());
|
||||
try {
|
||||
repackager.repackage(target, libraries);
|
||||
}
|
||||
catch (IOException ex) {
|
||||
throw new MojoExecutionException(ex.getMessage(), ex);
|
||||
}
|
||||
if (!source.equals(target)) {
|
||||
getLog().info(
|
||||
"Attaching archive: " + target + ", with classifier: "
|
||||
+ this.classifier);
|
||||
this.projectHelper.attachArtifact(this.project, this.project.getPackaging(),
|
||||
this.classifier, target);
|
||||
}
|
||||
}
|
||||
|
||||
private File getTargetFile() {
|
||||
String classifier = (this.classifier == null ? "" : this.classifier.trim());
|
||||
if (classifier.length() > 0 && !classifier.startsWith("-")) {
|
||||
classifier = "-" + classifier;
|
||||
}
|
||||
return new File(this.outputDirectory, this.finalName + classifier + "."
|
||||
+ this.project.getPackaging());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -28,15 +28,15 @@ import org.apache.maven.plugins.shade.resource.ResourceTransformer;
|
||||
|
||||
/**
|
||||
* Extension for the <a href="http://maven.apache.org/plugins/maven-shade-plugin/">Maven
|
||||
* shade plugin</a> to allow properties files (e.g. <code>META-INF/spring.factories</code>
|
||||
* ) to be merged without losing any information.
|
||||
* shade plugin</a> to allow properties files (e.g. {@literal META-INF/spring.factories})
|
||||
* to be merged without losing any information.
|
||||
*
|
||||
* @author Dave Syer
|
||||
*/
|
||||
public class PropertiesMergingResourceTransformer implements ResourceTransformer {
|
||||
|
||||
private String resource; // Set this in pom configuration with
|
||||
// <resource>...</resource>
|
||||
// Set this in pom configuration with <resource>...</resource>
|
||||
private String resource;
|
||||
|
||||
private Properties data = new Properties();
|
||||
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
package org.springframework.boot.maven;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
@@ -26,12 +27,15 @@ import java.util.List;
|
||||
|
||||
import org.apache.maven.artifact.Artifact;
|
||||
import org.apache.maven.model.Resource;
|
||||
import org.apache.maven.plugin.AbstractMojo;
|
||||
import org.apache.maven.plugin.MojoExecutionException;
|
||||
import org.apache.maven.plugin.MojoFailureException;
|
||||
import org.apache.maven.plugins.annotations.LifecyclePhase;
|
||||
import org.apache.maven.plugins.annotations.Mojo;
|
||||
import org.apache.maven.plugins.annotations.Parameter;
|
||||
import org.apache.maven.plugins.annotations.ResolutionScope;
|
||||
import org.apache.maven.project.MavenProject;
|
||||
import org.springframework.boot.launcher.tools.MainClassFinder;
|
||||
|
||||
/**
|
||||
* MOJO that can be used to run a executable archive application directly from Maven.
|
||||
@@ -39,7 +43,13 @@ import org.apache.maven.plugins.annotations.ResolutionScope;
|
||||
* @author Phillip Webb
|
||||
*/
|
||||
@Mojo(name = "run", requiresProject = true, defaultPhase = LifecyclePhase.VALIDATE, requiresDependencyResolution = ResolutionScope.TEST)
|
||||
public class RunMojo extends AbstractExecutableArchiveMojo {
|
||||
public class RunMojo extends AbstractMojo {
|
||||
|
||||
/**
|
||||
* The Maven project.
|
||||
*/
|
||||
@Parameter(defaultValue = "${project}", readonly = true, required = true)
|
||||
private MavenProject project;
|
||||
|
||||
/**
|
||||
* Add maven resources to the classpath directly, this allows live in-place editing or
|
||||
@@ -57,12 +67,26 @@ public class RunMojo extends AbstractExecutableArchiveMojo {
|
||||
@Parameter(property = "run.arguments")
|
||||
private String[] arguments;
|
||||
|
||||
/**
|
||||
* The name of the main class. If not specified the first compiled class found that
|
||||
* contains a 'main' method will be used.
|
||||
*/
|
||||
@Parameter
|
||||
private String mainClass;
|
||||
|
||||
/**
|
||||
* Folders that should be added to the classpath.
|
||||
*/
|
||||
@Parameter
|
||||
private String[] folders;
|
||||
|
||||
/**
|
||||
* Directory containing the classes and resource files that should be packaged into
|
||||
* the archive.
|
||||
*/
|
||||
@Parameter(defaultValue = "${project.build.outputDirectory}", required = true)
|
||||
private File classesDirectrory;
|
||||
|
||||
@Override
|
||||
public void execute() throws MojoExecutionException, MojoFailureException {
|
||||
final String startClassName = getStartClass();
|
||||
@@ -75,19 +99,35 @@ public class RunMojo extends AbstractExecutableArchiveMojo {
|
||||
threadGroup.rethrowUncaughtException();
|
||||
}
|
||||
|
||||
private final String getStartClass() throws MojoExecutionException {
|
||||
String mainClass = this.mainClass;
|
||||
if (mainClass == null) {
|
||||
try {
|
||||
mainClass = MainClassFinder.findMainClass(this.classesDirectrory);
|
||||
}
|
||||
catch (IOException ex) {
|
||||
throw new MojoExecutionException(ex.getMessage(), ex);
|
||||
}
|
||||
}
|
||||
if (mainClass == null) {
|
||||
throw new MojoExecutionException("Unable to find a suitable main class, "
|
||||
+ "please add a 'mainClass' property");
|
||||
}
|
||||
return mainClass;
|
||||
}
|
||||
|
||||
private ClassLoader getClassLoader() throws MojoExecutionException {
|
||||
URL[] urls = getClassPathUrls();
|
||||
return new URLClassLoader(urls);
|
||||
}
|
||||
|
||||
private URL[] getClassPathUrls() throws MojoExecutionException {
|
||||
ArchiveHelper archiveHelper = getArchiveHelper();
|
||||
try {
|
||||
List<URL> urls = new ArrayList<URL>();
|
||||
addUserDefinedFolders(urls);
|
||||
addResources(urls);
|
||||
addProjectClasses(urls);
|
||||
addDependencies(archiveHelper, urls);
|
||||
addDependencies(urls);
|
||||
return urls.toArray(new URL[urls.size()]);
|
||||
}
|
||||
catch (MalformedURLException ex) {
|
||||
@@ -105,21 +145,20 @@ public class RunMojo extends AbstractExecutableArchiveMojo {
|
||||
|
||||
private void addResources(List<URL> urls) throws MalformedURLException {
|
||||
if (this.addResources) {
|
||||
for (Resource resource : getProject().getResources()) {
|
||||
for (Resource resource : this.project.getResources()) {
|
||||
urls.add(new File(resource.getDirectory()).toURI().toURL());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void addProjectClasses(List<URL> urls) throws MalformedURLException {
|
||||
urls.add(getClassesDirectory().toURI().toURL());
|
||||
urls.add(this.classesDirectrory.toURI().toURL());
|
||||
}
|
||||
|
||||
private void addDependencies(ArchiveHelper archiveHelper, List<URL> urls)
|
||||
throws MalformedURLException {
|
||||
for (Artifact artifact : getProject().getArtifacts()) {
|
||||
private void addDependencies(List<URL> urls) throws MalformedURLException {
|
||||
for (Artifact artifact : this.project.getArtifacts()) {
|
||||
if (artifact.getFile() != null) {
|
||||
if (archiveHelper.getArtifactDestination(artifact) != null) {
|
||||
if (!Artifact.SCOPE_TEST.equals(artifact.getScope())) {
|
||||
urls.add(artifact.getFile().toURI().toURL());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,97 +0,0 @@
|
||||
/*
|
||||
* Copyright 2012-2013 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.boot.maven;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
|
||||
import org.codehaus.plexus.util.IOUtil;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.TemporaryFolder;
|
||||
import org.springframework.boot.maven.MainClassFinder;
|
||||
import org.springframework.boot.maven.sample.ClassWithMainMethod;
|
||||
import org.springframework.boot.maven.sample.ClassWithoutMainMethod;
|
||||
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
/**
|
||||
* Tests for {@link MainClassFinder}.
|
||||
*
|
||||
* @author Phillip Webb
|
||||
*/
|
||||
public class MainClassFinderTests {
|
||||
|
||||
@Rule
|
||||
public TemporaryFolder temporaryFolder = new TemporaryFolder();
|
||||
|
||||
@Test
|
||||
public void findMainClass() throws Exception {
|
||||
File expected = copyToTemp("b.class", ClassWithMainMethod.class);
|
||||
copyToTemp("a.class", ClassWithoutMainMethod.class);
|
||||
File actual = MainClassFinder.findMainClassFile(this.temporaryFolder.getRoot());
|
||||
assertThat(actual, equalTo(expected));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void findMainClassInSubFolder() throws Exception {
|
||||
File expected = copyToTemp("a/b/c/d.class", ClassWithMainMethod.class);
|
||||
copyToTemp("a/b/c/e.class", ClassWithoutMainMethod.class);
|
||||
copyToTemp("a/b/f.class", ClassWithoutMainMethod.class);
|
||||
File actual = MainClassFinder.findMainClassFile(this.temporaryFolder.getRoot());
|
||||
assertThat(actual, equalTo(expected));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void usesBreadthFirst() throws Exception {
|
||||
File expected = copyToTemp("a/b.class", ClassWithMainMethod.class);
|
||||
copyToTemp("a/b/c/e.class", ClassWithMainMethod.class);
|
||||
File actual = MainClassFinder.findMainClassFile(this.temporaryFolder.getRoot());
|
||||
assertThat(actual, equalTo(expected));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void findsClassName() throws Exception {
|
||||
copyToTemp("org/test/MyApp.class", ClassWithMainMethod.class);
|
||||
assertThat(MainClassFinder.findMainClass(this.temporaryFolder.getRoot()),
|
||||
equalTo("org.test.MyApp"));
|
||||
|
||||
}
|
||||
|
||||
private File copyToTemp(String filename, Class<?> classToCopy) throws IOException {
|
||||
String[] paths = filename.split("\\/");
|
||||
File file = this.temporaryFolder.getRoot();
|
||||
for (String path : paths) {
|
||||
file = new File(file, path);
|
||||
}
|
||||
file.getParentFile().mkdirs();
|
||||
InputStream inputStream = getClass().getResourceAsStream(
|
||||
"/" + classToCopy.getName().replace(".", "/") + ".class");
|
||||
OutputStream outputStream = new FileOutputStream(file);
|
||||
try {
|
||||
IOUtil.copy(inputStream, outputStream);
|
||||
}
|
||||
finally {
|
||||
outputStream.close();
|
||||
}
|
||||
return file;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user