mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
external artifact builder: show warning instead of creating empty jar [rev by Dmitry A.]
This commit is contained in:
@@ -135,9 +135,9 @@ public class JarsBuilder {
|
||||
}
|
||||
|
||||
private void buildJar(final JarInfo jar) throws IOException {
|
||||
final String emptyArchiveMessage = "Archive '" + jar.getPresentableDestination() + "' doesn't contain files so it won't be created";
|
||||
if (jar.getContent().isEmpty()) {
|
||||
final String message = "Archive '" + jar.getPresentableDestination() + "' has no files so it won't be created";
|
||||
myContext.processMessage(new CompilerMessage(IncArtifactBuilder.BUILDER_NAME, BuildMessage.Kind.WARNING, message));
|
||||
myContext.processMessage(new CompilerMessage(IncArtifactBuilder.BUILDER_NAME, BuildMessage.Kind.WARNING, emptyArchiveMessage));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -151,8 +151,8 @@ public class JarsBuilder {
|
||||
Manifest manifest = loadManifest(jar, packedFilePaths);
|
||||
final JarOutputStream jarOutputStream = createJarOutputStream(jarFile, manifest);
|
||||
|
||||
final THashSet<String> writtenPaths = new THashSet<String>();
|
||||
try {
|
||||
final THashSet<String> writtenPaths = new THashSet<String>();
|
||||
if (manifest != null) {
|
||||
writtenPaths.add(JarFile.MANIFEST_NAME);
|
||||
}
|
||||
@@ -187,16 +187,31 @@ public class JarsBuilder {
|
||||
}
|
||||
}
|
||||
|
||||
if (writtenPaths.isEmpty()) {
|
||||
myContext.processMessage(new CompilerMessage(IncArtifactBuilder.BUILDER_NAME, BuildMessage.Kind.WARNING, emptyArchiveMessage));
|
||||
return;
|
||||
}
|
||||
|
||||
final ProjectBuilderLogger logger = myContext.getLoggingManager().getProjectBuilderLogger();
|
||||
if (logger.isEnabled()) {
|
||||
|
||||
logger.logCompiledPaths(packedFilePaths, IncArtifactBuilder.BUILDER_NAME, "Packing files:");
|
||||
}
|
||||
myOutputConsumer.registerOutputFile(targetJarPath, packedFilePaths);
|
||||
|
||||
}
|
||||
finally {
|
||||
jarOutputStream.close();
|
||||
if (writtenPaths.isEmpty()) {
|
||||
try {
|
||||
jarOutputStream.close();
|
||||
}
|
||||
catch (IOException ignored) {
|
||||
}
|
||||
FileUtil.delete(jarFile);
|
||||
myBuiltJars.remove(jar);
|
||||
}
|
||||
else {
|
||||
jarOutputStream.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+22
@@ -303,6 +303,28 @@ public class ArtifactBuilderTest extends ArtifactBuilderTestCase {
|
||||
assertOutput(a, fs().archive("a.jar").file("a.txt").end().file("b.txt"));
|
||||
}
|
||||
|
||||
public void testDoNotCreateEmptyArchive() {
|
||||
String file = createFile("dir/a.txt");
|
||||
JpsArtifact a = addArtifact(archive("a.jar").parentDirCopy(file));
|
||||
delete(file);
|
||||
buildAll();
|
||||
assertEmptyOutput(a);
|
||||
}
|
||||
|
||||
public void testDoNotCreateEmptyArchiveInsideArchive() {
|
||||
String file = createFile("dir/a.txt");
|
||||
JpsArtifact a = addArtifact(archive("a.jar").archive("inner.jar").parentDirCopy(file));
|
||||
delete(file);
|
||||
buildAll();
|
||||
assertEmptyOutput(a);
|
||||
}
|
||||
|
||||
public void testDoNotCreateEmptyArchiveFromExtractedDirectory() {
|
||||
final JpsArtifact a = addArtifact("a", archive("a.jar").dir("dir").extractedDir(getJUnitJarPath(), "/xxx/"));
|
||||
buildAll();
|
||||
assertEmptyOutput(a);
|
||||
}
|
||||
|
||||
private static void createFileInArtifactOutput(JpsArtifact a, final String fileName) throws IOException {
|
||||
assertTrue(new File(a.getOutputPath(), fileName).createNewFile());
|
||||
}
|
||||
|
||||
+2
-2
@@ -97,8 +97,8 @@ public abstract class ArtifactBuilderTestCase extends JpsBuildTestCase {
|
||||
return FileUtil.toSystemIndependentName(file.getAbsolutePath());
|
||||
}
|
||||
|
||||
protected static void assertEmptyOutput(JpsArtifact a1) {
|
||||
assertOutput(a1, fs());
|
||||
protected static void assertEmptyOutput(JpsArtifact a) {
|
||||
assertOutput(a, fs());
|
||||
}
|
||||
|
||||
protected void assertBuildFailed(JpsArtifact a) {
|
||||
|
||||
Reference in New Issue
Block a user