Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error [URI scheme is not "file"] if some processSourceArtifacts are specified #93

Closed
borramTAS opened this issue Feb 9, 2021 · 25 comments
Assignees
Milestone

Comments

@borramTAS
Copy link

borramTAS commented Feb 9, 2021

Problem

We need to process some JPA Metamodel that residing in some external dependencies, this is the plugin configuration:

<plugin>
    <groupId>org.bsc.maven</groupId>
    <artifactId>maven-processor-plugin</artifactId>
    <version>4.5</version>
    <executions>
        <execution>
            <id>jpa-metamodel-process</id>
            <goals>
                <goal>process</goal>
            </goals>
            <phase>generate-sources</phase>
            <configuration>
                <outputDirectory>${project.build.directory}/generated-sources/java/jpametamodel
                </outputDirectory>
                <processors>
                    <processor>org.hibernate.jpamodelgen.JPAMetaModelEntityProcessor</processor>
                </processors>
                <processSourceArtifacts>
                    <processSourceArtifact>it.XXXXXXXX.YYYYYY.ZZZZZZZZZZ:admin:source
                    </processSourceArtifact>
                </processSourceArtifacts>
            </configuration>
        </execution>
    </executions>
    <dependencies>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-jpamodelgen</artifactId>
            <version>${hibernate.version}</version>
        </dependency>
    </dependencies>
</plugin>

But when we run a clean compile we receive the following error:

[DEBUG] javac option: -source
[DEBUG] javac option: 11
[DEBUG] javac option: -target
[DEBUG] javac option: 11
[DEBUG] javac option: -encoding
[DEBUG] javac option: UTF-8
[ERROR] diagnostic: URI scheme is not "file"
[ERROR] error on execute: use -X to have details 
[DEBUG] 
java.lang.Exception: error during compilation
    at org.bsc.maven.plugin.processor.AbstractAnnotationProcessorMojo.executeWithExceptionsHandled (AbstractAnnotationProcessorMojo.java:875)
    at org.bsc.maven.plugin.processor.AbstractAnnotationProcessorMojo.execute (AbstractAnnotationProcessorMojo.java:468)

Environment

Apache Maven 3.6.3 (cecedd343002696d0abb50b32b541b8a6ba2883f)
Maven home: C:\Users\borram\AppData\Local\JetBrains\IntelliJ IDEA 2019.3.1\plugins\maven\lib\maven3
Java version: 11.0.6, vendor: AdoptOpenJDK, runtime: C:\opt\jdks\adoptopenjdk.net\jdk-11.0.6+10
Default locale: en_US, platform encoding: UTF-8
OS name: "windows 10", version: "10.0", arch: "amd64", family: "windows"

If I remove the dependency: <processSourceArtifact>it.XXXXXXXX.YYYYYY.ZZZZZZZZZZ:admin:source</processSourceArtifact> everything works. I also checked the dependency and it looks like a correct JAR.

maven.log

Many thanks for any suggestion
Marino

@bsorrentino
Copy link
Owner

Hi @borramTAS

Keep in mind that when you use <processSourceArtifact>it.XXXXXXXX.YYYYYY.ZZZZZZZZZZ:admin:source</processSourceArtifact> such sources will be added to compilation phase.

Form the log seems to me that the error is originated by sources that You've attached ...

@borramTAS
Copy link
Author

Hi @bsorrentino

I have tried with others 5 different sources JAR, but the result is the same.

The directory target\generated-sources\apt is always empty.

@bsorrentino
Copy link
Owner

Hi @borramTAS, let me check if there are some problem during processing of source package.

Could you provide me an example of what you refers as

<processSourceArtifact>it.XXXXXXXX.YYYYYY.ZZZZZZZZZZ:admin:source</processSourceArtifact>

thanks in advance

@borramTAS
Copy link
Author

Hi @bsorrentino, unfortunately I cannot distribute the content of those JARs, but I also did a test with more common jars such as: commons-collections:commons-collections:source, I don't know if it makes sense.

[DEBUG] ** Discovered 273 java sources in C:\m2rpy\commons-collections\commons-collections\3.2.2\commons-collections-3.2.2-sources.jar
[DEBUG] PROCESSOR COMPILER FORKED!
[DEBUG] javac option: UTF-8
[ERROR] diagnostic: URI scheme is not "file"
[ERROR] error on execute: use -X to have details 

@borramTAS
Copy link
Author

Update: I have tried with a new project with a new completely new JAR that include only one @MappedSuperclass, but the result is always the same.

@bsorrentino
Copy link
Owner

Hi @borramTAS

I've done test using the following configuration

        <dependencies>

            <dependency>
                <groupId>commons-collections</groupId>
                <artifactId>commons-collections</artifactId>
                <version>3.2.1</version>
                <classifier>sources</classifier>
            </dependency>
        </dependencies>
        <build>
            <plugins>
                <plugin>
                <groupId>org.bsc.maven</groupId>
                <artifactId>maven-processor-plugin</artifactId>
                <version>${project.version}</version>
                <executions>
                    <execution>
                        <id>issue93</id>
                        <goals><goal>process</goal></goals>
                        <phase>compile</phase>
                        <configuration>
                            <appendSourceArtifacts>true</appendSourceArtifacts>
                            <processSourceArtifacts>
                                <processSourceArtifact>commons-collections:commons-collections</processSourceArtifact>
                            </processSourceArtifacts>
                            <failOnError>true</failOnError>
                            <processors>
                                <processor>org.bsc.maven.plugin.processor.test.TestGenerateSourceProcessor</processor>
                            </processors>
                        </configuration>
                    </execution>
                </executions>
                </plugin>

            </plugins>

        </build>

and all worked as expected

Note:

I've used the 5.0-SNAPSHOT version

@borramTAS
Copy link
Author

Hi @bsorrentino, it's works because the dependencies is in the classpath:

        <dependencies>
            <dependency>
                <groupId>commons-collections</groupId>
                <artifactId>commons-collections</artifactId>
                <version>3.2.1</version>
                <classifier>sources</classifier>
            </dependency>
        </dependencies>

If you remove:

                            <processSourceArtifacts>
                                <processSourceArtifact>commons-collections:commons-collections</processSourceArtifact>
                            </processSourceArtifacts>

you get the same result, and processSourceArtifacts is ignored, you can check in the logs. But that's not my goal. I don't want to insert the dependency of the sources, it is the purpose of the processSourceArtifacts.

@bsorrentino
Copy link
Owner

bsorrentino commented Feb 14, 2021

Hi @borramTAS

The goal of <processSourceArtifacts> configuration is to select what dependency artifacts with classifier sources we want add to annotation processing.
This has been originally implemented to process additional sources in processor.( the first use case was a processor for GWT)

For how it is implemented, the dependency declaration is required (you can also put them as optional)

@borramTAS
Copy link
Author

Hi @bsorrentino,

I did a test with your project (forked), and if I activate the toolchain profile I get the same error as mine, if I deactivate it everything works.

      <dependency>
          <groupId>it.mydependency.with.jpa</groupId>
          <artifactId>core-jpa</artifactId>
          <version>1.1.164</version>
      </dependency>
  </dependencies>

<build>

<pluginManagement>
    <plugins>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>build-helper-maven-plugin</artifactId>
            <version>1.7</version>
        </plugin>
    </plugins>

</pluginManagement>
<plugins>

<!--
===================================================================
PROCESSOR PLUGIN
===================================================================
 -->

    <plugin>
        <groupId>org.bsc.maven</groupId>
        <artifactId>maven-processor-plugin</artifactId>
        <version>${project.version}</version>
        <dependencies>
            <!--
            <dependency>
                <groupId>org.bsc</groupId>
                <artifactId>jaxrs-wiki-processor</artifactId>
                <version>2.2</version>
            </dependency>
            -->
            <dependency>
                <groupId>org.hibernate</groupId>
                <artifactId>hibernate-jpamodelgen</artifactId>
                <version>5.4.20.Final</version>
            </dependency>
        </dependencies>
        <executions>

            <execution>

                <id>process-test</id>
                <goals>
                    <goal>process-test</goal>
                </goals>
                <phase>process-test-classes</phase>
                <configuration>
                    <outputDirectory>${basedir}/src/site</outputDirectory>

                    <additionalSourceDirectories>
                        <item>${user.home}/src</item>
                        <item>./src/main/java</item>
                    </additionalSourceDirectories>

                    <failOnError>true</failOnError>
                    <processors>
<!--                        <processor>org.bsc.maven.plugin.processor.test.TestWikiProcessor</processor>-->
                        <processor>org.hibernate.jpamodelgen.JPAMetaModelEntityProcessor</processor>
                    </processors>

                    <processSourceArtifacts>
                        <processSourceArtifact>it.mydependency.with.jpa:core-jpa</processSourceArtifact>
                    </processSourceArtifacts>
                    <options>
                        <test>true</test>
                    </options>
                </configuration>

@borramTAS
Copy link
Author

This line throw the exception:

public class AnnotationProcessorCompiler implements JavaCompiler {
...
 sourceFiles.add( new java.io.File( src.toUri() ) );
...
}
        final java.util.Set<java.io.File> sourceFiles = 
                new java.util.HashSet<java.io.File>();
        for( JavaFileObject src : compilationUnits ) {
            sourceFiles.add( new java.io.File( src.toUri() ) );
        }

@bsorrentino
Copy link
Owner

bsorrentino commented Mar 1, 2021

Hi @borramTAS thanks for your effort.

Finally I understood the problem that happen exclusively when use toolchain because the Plexus API, that manages the forked java compiler, has not the ability to read entry directly from jar but requires that them are on the file system

I'm going to fix it

bsorrentino pushed a commit that referenced this issue Mar 1, 2021
added UnzipService to extract Source Artifacts to the file system
@bsorrentino bsorrentino added this to the 5.0 milestone Mar 1, 2021
@bsorrentino
Copy link
Owner

Hi @borramTAS

fixed has been released in 5.0-SNAPSHOT

I'll arrange an official release soon

@borramTAS
Copy link
Author

I was investigating and had come to the same conclusion. It seemed strange to me that it could work before.

I await the updated version 5.0-SNAPSHOT.

Many thanks for the support.

@bsorrentino
Copy link
Owner

bsorrentino commented Mar 1, 2021

Hi @borramTAS

The reason it (now) clear:

Without using toolchain (i.e. run an external jvm compiler) there isn't a problem.

So, for who like me don't use toolchain, it is always worked well

@borramTAS
Copy link
Author

The reason it (now) clear:
Without using toolchain (i.e. run an external jvm compiler) there isn't a problem.

The problem is now very clear to me too 👍

So, for who like me don't use toolchain, it is always worked well

Unfortunately we always use the toolchain :-(

@bsorrentino
Copy link
Owner

don't worry new release is coming .... will be 5.0-rc1

@bsorrentino
Copy link
Owner

fix released in 5.0-rc1

@borramTAS
Copy link
Author

Hi @bsorrentino,

Thanks so much for the quick intervention, I did a test and now for a single JAR it seems to work, I have an error (error: cannot find symbol) in case I use multiple JARs, it seems that the second JAR is not included. I'll have to investigate.

            <addCompileSourceRoots>true</addCompileSourceRoots>
            <processSourceArtifacts>
                <processSourceArtifact>it.xxxxx.yyyyy.zzzzzz:core:sources</processSourceArtifact><-- OK
                <processSourceArtifact>it.xxxxx.yyyyy:zzzzzz:admin:sources</processSourceArtifact><-- Not found
            </processSourceArtifacts>

@bsorrentino
Copy link
Owner

Hi @borramTAS

Let me know the results of investigantion. I'll do too

@bsorrentino
Copy link
Owner

Hi @borramTAS

I tested and it worked, did you forget to add related dependency ?

@borramTAS
Copy link
Author

Hi @bsorrentino I think I have identified the problem, I have two dependencies with the same groupId, the second is always discarded:

        <processSourceArtifacts>
            <processSourceArtifact>it.xxxxxxxx.yyyyyyy.rrrrrrr:core:sources</processSourceArtifact>
            <processSourceArtifact>it.xxxxxxxx.yyyyyyy.rrrrrrr:admin:sources</processSourceArtifact>
        </processSourceArtifacts>

At this statement return dep.getArtifactId().equals(token[1]); the secondo one will be discarded:

            if( token.length == 1 ) return true;
            
            if( token[1].equals("*") ) return true;

            return dep.getArtifactId().equals(token[1]);
            
        }
dep.getArtifactId() == 'admin'
token[1] == 'core'

bsorrentino pushed a commit that referenced this issue Mar 6, 2021
@bsorrentino
Copy link
Owner

Hi @borramTAS

I've tested the following configuration with success (take a look to here)

Plugin

                            <processSourceArtifacts>
                                <processSourceArtifact>commons-collections:commons-collections</processSourceArtifact>
                                <processSourceArtifact>org.codehaus.plexus:plexus-tools</processSourceArtifact>
                                <processSourceArtifact>org.apache.commons:commons-text</processSourceArtifact>
                                <processSourceArtifact>org.apache.commons:commons-lang3</processSourceArtifact>
                            </processSourceArtifacts>

Dependencies

            <dependency>
                <groupId>commons-collections</groupId>
                <artifactId>commons-collections</artifactId>
                <version>3.2.2</version>
                <classifier>sources</classifier>
            </dependency>
            <dependency>
                <groupId>org.codehaus.plexus</groupId>
                <artifactId>plexus-compiler-javac</artifactId>
                <version>2.8.8</version>
                <classifier>sources</classifier>
            </dependency>
            <dependency>
              <groupId>org.apache.commons</groupId>
              <artifactId>commons-text</artifactId>
              <version>1.9</version>
              <classifier>sources</classifier>
            </dependency>
            <dependency>
              <groupId>org.apache.commons</groupId>
              <artifactId>commons-lang3</artifactId>
              <version>3.12.0</version>
              <classifier>sources</classifier>
            </dependency>

@borramTAS
Copy link
Author

If you remove <classifier>sources</classifier> only one is correctly unzipped:

        <dependencies>

            <dependency>
                <groupId>commons-collections</groupId>
                <artifactId>commons-collections</artifactId>
                <version>3.2.2</version>
<!--                <classifier>sources</classifier>-->
            </dependency>
            <dependency>
                <groupId>org.codehaus.plexus</groupId>
                <artifactId>plexus-compiler-javac</artifactId>
                <version>2.8.8</version>
<!--                <classifier>sources</classifier>-->
            </dependency>
            <dependency>
              <groupId>org.apache.commons</groupId>
              <artifactId>commons-text</artifactId>
              <version>1.9</version>
<!--              <classifier>sources</classifier>-->
            </dependency>
            <dependency>
              <groupId>org.apache.commons</groupId>
              <artifactId>commons-lang3</artifactId>
              <version>3.12.0</version>
<!--              <classifier>sources</classifier>-->
            </dependency>
          </dependencies>
[INFO] --- maven-processor-plugin:5.0-SNAPSHOT:process (issue93) @ maven-processor-plugin-test-app ---
[INFO] [100] sources succesfully extracted from artifact [org.apache.commons:commons-text:jar:sources:1.9] to:
 [C:\Users\borram\IdeaCEProjects\maven-annotation-plugin\test\app\target\extracted-sources\commons-text]
warning: [options] bootstrap class path not set in conjunction with -source 9
Note: Hibernate JPA 2 Static-Metamodel Generator 5.4.20.Final
1 warning

@bsorrentino
Copy link
Owner

If you want to use processSourceArtifact feature you must declare dependencies with sources classifier

@borramTAS
Copy link
Author

At this moment it is not clear to me why one works and [N] does not, but with sources it now works for me too.

Many thanks again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants