lastnpe / eclipse-null-eea-augments

Eclipse External null Annotations (EEA) repository
http://lastnpe.org
Eclipse Public License 2.0
41 stars 22 forks source link

Improve Documentation #147

Open yennor opened 2 years ago

yennor commented 2 years ago

I come here on a regular basis every few months, to see if I can integrate that into some projects. But so far I always failed (I gave up pretty quickly). The example project uses as parent org.lastnpe.eea.eea-root Can I just ignore that and only add it as a dependency? Is really everything in the plugin section needed? I guess the tycho compiler stuff is not needed for a normal project?

hello and lib uses as parent org.lastnpe.examples. I guess I can just add org.lastnpe.eea.eea-all as dependency and all the plugin configuration from org.lastnpe.examples?

Hello but not lib uses

    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-deploy-plugin</artifactId>
        <configuration>
          <skip>true</skip>
        </configuration>
      </plugin>
    </plugins>

what would be the difference there?

A minimal example, with a completely independent project which doesn't use org.lastnpe.eea.eea-root as parent would make things easier for people which are no maven mages.

J-N-K commented 2 years ago

The important parts could look like

        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-compiler-plugin</artifactId>
          <version>3.8.1</version>
          <configuration>
            <compilerId>eclipse</compilerId>
            <compilerArguments>
              <annotationpath>CLASSPATH</annotationpath>
              <classpath>${project.build.directory}/dependency</classpath>
              <properties>${basedirRoot}/tools/org.eclipse.jdt.core.prefs</properties>
            </compilerArguments>
            <showWarnings>true</showWarnings>
            <showDeprecation>true</showDeprecation>
          </configuration>
          <dependencies>
            <dependency>
              <groupId>org.codehaus.plexus</groupId>
              <artifactId>plexus-compiler-eclipse</artifactId>
              <version>2.8.8</version>
            </dependency>
            <dependency>
              <groupId>org.eclipse.jdt</groupId>
              <artifactId>ecj</artifactId>
              <version>3.23.0</version>
            </dependency>
          </dependencies>
        </plugin>
        <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-dependency-plugin</artifactId>
        <version>3.1.1</version>
        <executions>
          <execution>
            <id>unpack-eea</id>
            <goals>
              <goal>unpack</goal>
            </goals>
            <configuration>
              <artifactItems>
                <artifactItem>
                  <groupId>org.lastnpe.eea</groupId>
                  <artifactId>eea-all</artifactId>
                  <version>${eea.version}</version>
                  <overWrite>true</overWrite>
                </artifactItem>
              </artifactItems>
            </configuration>
          </execution>
        </executions>
      </plugin>

and a dependency

    <dependency>
      <groupId>org.lastnpe.eea</groupId>
      <artifactId>eea-all</artifactId>
      <version>${eea.version}</version>
    </dependency>
yennor commented 2 years ago

Thanks a lot. Eclipse complains about Plugin execution not covered by lifecycle configuration: org.apache.maven.plugins:maven-dependency-plugin:3.1.2:unpack (execution: unpack-eea, phase: process-sources) But I guess I can just ignore that?

I've activated "Search for external annotations in Project Path", no idea if that would be necessary. Is there anything else I'd need to change? How can I test its working? I though something like: LocalDateTime.now().minusDays(1); Shouldn't show a Null type safety warning anymore when it's working? (Right now it still is)

J-N-K commented 2 years ago

Sorry, I can't help you with Eclipse, I'm using IntelliJ IDEA.

Regarding the lifecycle: ou probably need something like this:

        <plugin>
          <groupId>org.eclipse.m2e</groupId>
          <artifactId>lifecycle-mapping</artifactId>
          <version>1.0.0</version>
          <configuration>
            <lifecycleMappingMetadata>
              <pluginExecutions>
                <pluginExecution>
                  <pluginExecutionFilter>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-dependency-plugin</artifactId>
                    <versionRange>[3.0.0,)</versionRange>
                    <goals>
                      <goal>unpack</goal>
                      <goal>unpack-dependencies</goal>
                    </goals>
                  </pluginExecutionFilter>
                  <action>
                    <execute/>
                  </action>
                </pluginExecution>
              </pluginExecutions>
            </lifecycleMappingMetadata>
          </configuration>
        </plugin>
kwin commented 2 years ago

You can use https://github.com/aneesh-joseph/m2e-maven-dependency-plugin to execute unpack in the Eclipse incremental build.

yennor commented 2 years ago

you're way too fast. by adding the fragment from @J-N-K to The error disappeared. But I still don't have the feeling it's working. Does somebody have me a one liner, with which I can test it? (Like without eea it gives a warning because of possible null pointer access, and with eea it doesn't).

yennor commented 2 years ago

I've just looked into it again. And decided to start by zero, but I didn-t and didn't manage to get it working with the examples and above help. Until I've found the setting "java compiler"/"errors warning"/"Search for annotations in all build path locations". I've activated it, and it-s working. (I'm talking about Eclipse. I'ce also got installed: eclipse-external-annotations-m2e-plugin. I didn-t test if it works without it.) The only entry in the pom.xml necessary is:

    <dependency>
      <groupId>org.lastnpe.eea</groupId>
      <artifactId>eea-all</artifactId>
      <version>${eea.version}</version>
    </dependency>

you can test it eg. with:

    @NonNull
    private LocalDateTime test = LocalDateTime.now().minusDays(1);

Which usually would throw a warning, but doesn't anymore after activating that settings and adding the dependency.

If somebody could verifiy, that also workins in other setups than mine, then I guess it would help people a lot to update the docs.

agentgt commented 2 years ago

I don’t use last npe all annotations but instead use our own. Specifically the maven property that points to which eclipse workspace project (not maven project coord but workspace) works great for us. This only works with the m2e eea plugin.

I use some analog of the headless approach that is in the documentation albeit using the jar version of our EEA project.

One of the way to make Eclipse shutup about the headless compile mode is to use profiles.

sebthom commented 2 years ago

This works for me:

  1. in your Eclipse project create a build target (e.g. named "build.target") file like this, that loads the eea-all maven artifact as an eclipse plugin:

      <?xml version="1.0" encoding="UTF-8" standalone="no"?>
      <?pde version="3.8"?>
      <target includeMode="feature" name="My Plugin Build Target">
          <locations>
              <location includeAllPlatforms="false" includeConfigurePhase="true" includeMode="planner" includeSource="true" type="InstallableUnit">
                  <repository location="https://download.eclipse.org/releases/2021-12/"/>
                  <unit id="org.eclipse.equinox.executable.feature.group" version="0.0.0"/>
                  <unit id="org.eclipse.sdk.ide" version="0.0.0"/>
              </location>
    
              <location includeDependencyDepth="infinite" includeDependencyScopes="compile" includeSource="true" missingManifest="generate" type="Maven">
                  <dependencies>
                      <dependency>
                          <groupId>org.lastnpe.eea</groupId>
                          <artifactId>eea-all</artifactId>
                          <version>2.4.0</version>
                          <type>jar</type>
                      </dependency>
                  </dependencies>
                  <instructions><![CDATA[
      Bundle-Name:           Bundle derived from maven artifact ${mvnGroupId}:${mvnArtifactId}:${mvnVersion}
      version:               ${version_cleanup;${mvnVersion}}
      Bundle-SymbolicName:   ${mvnGroupId}.${mvnArtifactId}
      Bundle-Version:        ${version}
      Import-Package:        *;resolution:=optional
      Export-Package:        *;version="${version}";-noimport:=true
      DynamicImport-Package: *
      ]]></instructions>
              </location>
          </locations>
      </target>
  2. in your pom.xml advice tycho to use the build target file:
     <plugin>
        <!-- https://www.eclipse.org/tycho/sitedocs/target-platform-configuration/target-platform-configuration-mojo.html -->
        <groupId>org.eclipse.tycho</groupId>
        <artifactId>target-platform-configuration</artifactId>
        <version>${tycho.version}</version>
        <configuration>
           <pomDependencies>ignore</pomDependencies>
           <executionEnvironment>JavaSE-${java.version}</executionEnvironment>
           <target>
              <file>./build.target</file>
           </target>
        </configuration>
     </plugin>
  3. in Eclipse under Preferences/Target Platform select your build target file.
  4. in your plugin's build.properties reference the eea-all plugin:
      # https://codeiseasy.wordpress.com/2013/03/08/tycho-and-jdt-null-analysis/
      # JDT Null Analysis for Eclipse
      additional.bundles = org.eclipse.jdt.annotation,\
                           org.lastnpe.eea.eea-all
      # JDT Null Analysis types for Tycho
      jars.extra.classpath = platform:/plugin/org.eclipse.jdt.annotation,\
                             platform:/plugin/org.lastnpe.eea.eea-all