blutorange / closure-compiler-maven-plugin

Combine and minimize JavaScript with Closure Compiler.
http://blutorange.github.com/closure-compiler-maven-plugin
Apache License 2.0
52 stars 6 forks source link

Stream closed error occurs when m2e and skipMinify are on #46

Closed nakrephg closed 5 years ago

nakrephg commented 5 years ago

eclipse error message in pom.xml

Detailed error messages are as follows:


org.apache.maven.plugin.MojoExecutionException: Stream Closed
 at com.github.blutorange.maven.plugin.closurecompiler.plugin.MinifyMojo.execute(MinifyMojo.java:661)
 at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:134)
 at org.eclipse.m2e.core.internal.embedder.MavenImpl.execute(MavenImpl.java:331)
 at org.eclipse.m2e.core.internal.embedder.MavenImpl$11.call(MavenImpl.java:1362)
 at org.eclipse.m2e.core.internal.embedder.MavenImpl$11.call(MavenImpl.java:1)
 at org.eclipse.m2e.core.internal.embedder.MavenExecutionContext.executeBare(MavenExecutionContext.java:177)
 at org.eclipse.m2e.core.internal.embedder.MavenExecutionContext.execute(MavenExecutionContext.java:112)
 at org.eclipse.m2e.core.internal.embedder.MavenImpl.execute(MavenImpl.java:1360)
 at org.eclipse.m2e.core.project.configurator.MojoExecutionBuildParticipant.build(MojoExecutionBuildParticipant.java:52)
 at org.eclipse.m2e.core.internal.builder.MavenBuilderImpl.build(MavenBuilderImpl.java:137)
 at org.eclipse.m2e.core.internal.builder.MavenBuilder$1.method(MavenBuilder.java:172)
 at org.eclipse.m2e.core.internal.builder.MavenBuilder$1.method(MavenBuilder.java:1)
 at org.eclipse.m2e.core.internal.builder.MavenBuilder$BuildMethod$1$1.call(MavenBuilder.java:115)
 at org.eclipse.m2e.core.internal.embedder.MavenExecutionContext.executeBare(MavenExecutionContext.java:177)
 at org.eclipse.m2e.core.internal.embedder.MavenExecutionContext.execute(MavenExecutionContext.java:112)
 at org.eclipse.m2e.core.internal.builder.MavenBuilder$BuildMethod$1.call(MavenBuilder.java:105)
 at org.eclipse.m2e.core.internal.embedder.MavenExecutionContext.executeBare(MavenExecutionContext.java:177)
 at org.eclipse.m2e.core.internal.embedder.MavenExecutionContext.execute(MavenExecutionContext.java:151)
 at org.eclipse.m2e.core.internal.embedder.MavenExecutionContext.execute(MavenExecutionContext.java:99)
 at org.eclipse.m2e.core.internal.builder.MavenBuilder$BuildMethod.execute(MavenBuilder.java:86)
 at org.eclipse.m2e.core.internal.builder.MavenBuilder.build(MavenBuilder.java:200)
 at org.eclipse.core.internal.events.BuildManager$2.run(BuildManager.java:735)
 at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42) 
 at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:206)
 at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:246)
 at org.eclipse.core.internal.events.BuildManager$1.run(BuildManager.java:301)
 at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
 at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:304)
 at org.eclipse.core.internal.events.BuildManager.basicBuildLoop(BuildManager.java:360)
 at org.eclipse.core.internal.events.BuildManager.build(BuildManager.java:383)
 at org.eclipse.core.internal.events.AutoBuildJob.doBuild(AutoBuildJob.java:142)
 at org.eclipse.core.internal.events.AutoBuildJob.run(AutoBuildJob.java:232)
 at org.eclipse.core.internal.jobs.Worker.run(Worker.java:56) Caused by: java.io.IOException: Stream Closed
 at java.io.FileOutputStream.writeBytes(Native Method)
 at java.io.FileOutputStream.write(FileOutputStream.java:326)
 at java.io.BufferedOutputStream.write(BufferedOutputStream.java:122)
 at java.io.FilterOutputStream.write(FilterOutputStream.java:97)
 at org.eclipse.m2e.core.internal.builder.plexusbuildapi.ChangedFileOutputStream.writeIfNewOrChanged(ChangedFileOutputStream.java:101)
 at org.eclipse.m2e.core.internal.builder.plexusbuildapi.ChangedFileOutputStream.close(ChangedFileOutputStream.java:63)
 at com.github.blutorange.maven.plugin.closurecompiler.plugin.ProcessFilesTask.merge(ProcessFilesTask.java:366)
 at com.github.blutorange.maven.plugin.closurecompiler.plugin.ProcessFilesTask.processFiles(ProcessFilesTask.java:248)
 at com.github.blutorange.maven.plugin.closurecompiler.plugin.ProcessFilesTask.call(ProcessFilesTask.java:190)
 at com.github.blutorange.maven.plugin.closurecompiler.plugin.MinifyMojo.execute(MinifyMojo.java:655) ... 32 more 

This is my pom.xml setting.

<build>
    <finalName>test</finalName>
    <pluginManagement>
        <plugins>
            <plugin>
                <groupId>org.eclipse.m2e</groupId>
                <artifactId>lifecycle-mapping</artifactId>
                <version>1.0.0</version>
                <configuration>
                    <lifecycleMappingMetadata>
                        <pluginExecutions>
                            <pluginExecution>
                                <pluginExecutionFilter>
                                    <groupId>com.github.blutorange</groupId>
                                    <artifactId>closure-compiler-maven-plugin</artifactId>
                                    <versionRange>[2.0.0,)</versionRange>
                                    <goals>
                                        <goal>minify</goal>
                                    </goals>
                                </pluginExecutionFilter>
                                <action>
                                    <execute>
                                        <runOnIncremental>true</runOnIncremental>
                                    </execute>
                                </action>
                            </pluginExecutions>
                        </lifecycleMappingMetadata>
                    </configuration>
                </plugin>
            </plugins>
        </pluginManagement>
    <plugins>
        <plugin>
            <groupId>com.github.blutorange</groupId>
            <artifactId>closure-compiler-maven-plugin</artifactId>
            <version>2.1.0</version>
            <configuration>
                <encoding>UTF-8</encoding>
            </configuration>
            <executions>
                <execution>
                    <id>js-minify-custom</id>
                    <configuration>
                        <skipMinify>true</skipMinify>
                        <closureLanguageIn>STABLE</closureLanguageIn>
                        <closureLanguageOut>STABLE</closureLanguageOut>
                        <closureCompilationLevel>BUNDLE</closureCompilationLevel>
                        <outputFilename>skipMinify-${version}.js</outputFilename>
                        <includes>
                            <include>application/util/envUtils.js</include>
                            <include>application/util/*.js</include>
                            <include>application/**/*.js</include>
                            <include>library/**/*.js</include>
                        </includes>
                    </configuration>
                    <goals>
                        <goal>minify</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
    <!-- .... -->
</build>
blutorange commented 5 years ago

This is caused by the fact that the InputStream that is obtained in the m2e context throws an error when you try to call close twice. This makes it impossible to both wrap the stream and do it with a try-with-resource-block. I had already rewritten it when doing a minify, now I also changed the part when resources are only copied.

This only seems to happen under Windows, which makes it harder to test. I released and uploaded version 2.1.1. It should be available in maven central in the next few days. Please reopen if the issue persists.

nakrephg commented 5 years ago

Thank you for your prompt confirmation and correction. However, This fix does not work.

The same error occurred and only the line was changed.

ProcessFilesTask.java:366 -> ProcessFilesTask.java:396

....
.....
 at com.github.blutorange.maven.plugin.closurecompiler.plugin.ProcessFilesTask.merge(ProcessFilesTask.java:396)
 at com.github.blutorange.maven.plugin.closurecompiler.plugin.ProcessFilesTask.processFiles(ProcessFilesTask.java:248)
 at com.github.blutorange.maven.plugin.closurecompiler.plugin.ProcessFilesTask.call(ProcessFilesTask.java:190)
 at com.github.blutorange.maven.plugin.closurecompiler.plugin.MinifyMojo.execute(MinifyMojo.java:655) ... 31 more 

I do not know how to reopen this issue. Maybe I don't have authority.

blutorange commented 5 years ago

Thanks for the reply. There is one more part where I need to make the above-mentioned modification

blutorange commented 5 years ago

Hmm, I got around to test it with Window and it works for me even with version 2.1.0. Regardless, I made sure the OutputStream from m2e is not closed twice and released a snapshot version:

            <groupId>com.github.blutorange</groupId>
            <artifactId>closure-compiler-maven-plugin</artifactId>
            <version>2.2.0-SNAPSHOT</version>

Can you please try with that version whether that solves the error? (Make sure you restart eclipse after changing the version)

nakrephg commented 5 years ago

2.2.0-SNAPSHOT version was tested. The error message was confirmed to have disappeared.

The test was conducted with 2.1.1 and 2.1.0 and 2.2.0-SNAPSHOT in my development environment and the two previous versions confirmed that Stream Closed occurred and that it did not occur at 2.2.0-SNAPSHOT.

Thank you for the modification.

blutorange commented 5 years ago

Thank you for testing. I'm glad this is resolved.

I released version 2.2.0 now, which also includes the latest version of closure compiler.