Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion org.eclipse.m2e.apt.core/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %Bundle-Name
Bundle-SymbolicName: org.eclipse.m2e.apt.core;singleton:=true
Bundle-Version: 2.3.100.qualifier
Bundle-Version: 2.3.200.qualifier
Bundle-Localization: plugin
Require-Bundle: org.eclipse.core.runtime;bundle-version="[3.27.0,4.0.0)",
org.eclipse.core.resources,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@
@Override
public void configureClasspath(IClasspathDescriptor classpath, IProgressMonitor monitor) throws CoreException {

removeStaled(classpath);
AnnotationProcessorConfiguration configuration = getAnnotationProcessorConfiguration(monitor);

if((configuration == null) || !configuration.isAnnotationProcessingEnabled()) {
Expand All @@ -259,6 +260,10 @@
File outputFolder = new File(mavenProject.getBuild().getTestOutputDirectory());
addToClassPath(eclipseProject, generatedTestSourcesDirectory, outputFolder, classpath, true);
}
if (generatedSourcesDirectory != null || generatedTestSourcesDirectory != null) {
IJavaProject javaProject = JavaCore.create(eclipseProject);
javaProject.setRawClasspath(classpath.getEntries(), monitor);
}
}

protected abstract AnnotationProcessorConfiguration getAnnotationProcessorConfiguration(IProgressMonitor monitor)
Expand All @@ -283,11 +288,9 @@
IPath[] includes = new IPath[] {};
IPath[] excludes = new IPath[] {};

// If the source folder is non-nested, add it
// If the source folder doesn't exist, add it
if((generatedSourcesFolder != null) && generatedSourcesFolder.getProject().equals(project)) {
IClasspathEntryDescriptor enclosing = getEnclosingEntryDescriptor(classpath,
generatedSourcesFolder.getFullPath());
if((enclosing == null) || (getEntryDescriptor(classpath, generatedSourcesFolder.getFullPath()) != null)) {
if(getEntryDescriptor(classpath, generatedSourcesFolder.getFullPath()) == null) {
IClasspathEntryDescriptor entry = classpath.addSourceEntry(generatedSourcesFolder.getFullPath(), outputPath,
includes, excludes, true);
entry.setClasspathAttribute(IClasspathAttribute.IGNORE_OPTIONAL_PROBLEMS, "true"); //$NON-NLS-1$
Expand Down Expand Up @@ -322,7 +325,7 @@
* @return the {@link IClasspathEntryDescriptor} in the specified {@link IClasspathDescriptor} that is a prefix of the
* specified {@link IPath}
*/
private static IClasspathEntryDescriptor getEnclosingEntryDescriptor(IClasspathDescriptor classpath, IPath path) {

Check warning on line 328 in org.eclipse.m2e.apt.core/src/org/eclipse/m2e/apt/internal/AbstractAptConfiguratorDelegate.java

View check run for this annotation

Jenkins - M2E / Compiler

Unnecessary Code

NORMAL: The method getEnclosingEntryDescriptor(IClasspathDescriptor, IPath) from the type AbstractAptConfiguratorDelegate is never used locally
for(IClasspathEntryDescriptor cped : classpath.getEntryDescriptors()) {
if(cped.getPath().isPrefixOf(path)) {
return cped;
Expand All @@ -331,20 +334,25 @@
return null;
}

private IClasspathEntryDescriptor getEntryDescriptor(IClasspathDescriptor classpath, IPath fullPath) {
private void removeStaled(IClasspathDescriptor classpath) {
List<IPath> stalePaths = new ArrayList<>();
IClasspathEntryDescriptor matchingDescriptor = null;
for(IClasspathEntryDescriptor cped : classpath.getEntryDescriptors()) {
if(cped.getPath().equals(fullPath)) {
matchingDescriptor = cped;
} else if(Boolean.parseBoolean(cped.getClasspathAttributes().get(M2E_APT_KEY))) {
if(Boolean.parseBoolean(cped.getClasspathAttributes().get(M2E_APT_KEY))) {
stalePaths.add(cped.getPath());
}
}
for(IPath stalePath : stalePaths) {
classpath.removeEntry(stalePath);
}
return matchingDescriptor;
}

private IClasspathEntryDescriptor getEntryDescriptor(IClasspathDescriptor classpath, IPath fullPath) {
for(IClasspathEntryDescriptor cped : classpath.getEntryDescriptors()) {
if(cped.getPath().equals(fullPath)) {
return cped;
}
}
return null;
}

protected <T> T getParameterValue(String parameter, Class<T> asType, MojoExecution mojoExecution)
Expand Down
77 changes: 77 additions & 0 deletions org.eclipse.m2e.apt.tests/projects/nested/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>org.sample</groupId>
<artifactId>nested-test</artifactId>
<version>1.0-SNAPSHOT</version>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>
<dependency>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct</artifactId>
<version>1.6.3</version>
</dependency>
<dependency>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct-processor</artifactId>
<version>1.6.3</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.36</version>
<exclusions>
<exclusion>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct-processor</artifactId>
</exclusion>
</exclusions>
</dependency>

</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>3.2.0</version>
<executions>
<execution>
<?m2e execute onConfiguration,onIncremental?>
<id>add-source</id>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>${basedir}/target/generated-sources/</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<release>21</release>
<compilerArgs>
<arg>-parameters</arg>
<arg>-Xlint:all</arg>
</compilerArgs>

</configuration>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package org.mapper;

public class Main {
public static void main(String[] args) {
Person person = new Person(1l, "test");
PersonDto personDto = PersonMapper.INSTANCE.personToPersonDto(person);
System.out.println(personDto);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package org.mapper;

public class Person {

private Long id;
private String name;

public Person(Long id, String name) {
this.id = id;
this.name = name;
}

public Long getId() {
return id;
}

public void setId(Long id) {
this.id = id;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

@Override
public String toString() {
return "Person [id=" + id + ", name=" + name + "]";
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package org.mapper;

public class PersonDto {

private Long id;
private String name;

public Long getId() {
return id;
}

public void setId(Long id) {
this.id = id;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

@Override
public String toString() {
return "PersonDto [id=" + id + ", name=" + name + "]";
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package org.mapper;

import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;

@Mapper
public interface PersonMapper {
PersonMapper INSTANCE = Mappers.getMapper(PersonMapper.class);
PersonDto personToPersonDto(Person person);
}
Original file line number Diff line number Diff line change
Expand Up @@ -444,4 +444,13 @@ public void testDependencyManagement() throws Exception {
assertNotNull(javaProject);
assertNoErrors(p);
}

@Test
public void testNestedSourceFolders() throws Exception {
IProject project = importProject("projects/nested/pom.xml");
waitForJobsToComplete();
IJavaProject javaProject = JavaCore.create(project);
assertNotNull(javaProject);
assertNoErrors(project);
}
}
2 changes: 1 addition & 1 deletion org.eclipse.m2e.jdt/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %Bundle-Name
Bundle-SymbolicName: org.eclipse.m2e.jdt;singleton:=true
Bundle-Version: 2.5.100.qualifier
Bundle-Version: 2.5.101.qualifier
Bundle-Localization: plugin
Export-Package: org.eclipse.m2e.jdt,
org.eclipse.m2e.jdt.internal;x-friends:="org.eclipse.m2e.jdt.ui",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@
import org.eclipse.jdt.core.IClasspathAttribute;
import org.eclipse.jdt.core.IClasspathEntry;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jdt.internal.core.ClasspathEntry;
import org.eclipse.jdt.internal.core.util.Util;

import org.eclipse.m2e.jdt.IClasspathDescriptor;
import org.eclipse.m2e.jdt.IClasspathEntryDescriptor;
Expand Down Expand Up @@ -148,6 +151,59 @@
}
}

// check nested source entries
List<IClasspathEntry> toRemove = null;
List<IClasspathEntry> toAdd = null;
for(IClasspathEntry entry : result) {
int kind = entry.getEntryKind();
IPath entryPath = entry.getPath();
if(kind == IClasspathEntry.CPE_SOURCE) {
for(IClasspathEntry otherEntry : result) {
int otherKind = otherEntry.getEntryKind();
if(otherKind != IClasspathEntry.CPE_SOURCE)
continue;
if(entry != otherEntry) {
IPath otherPath = otherEntry.getPath();
char[][] inclusionPatterns, exclusionPatterns;
if(otherPath.isPrefixOf(entryPath) && !otherPath.equals(entryPath)
&& !Util.isExcluded(entryPath.append("*"), //$NON-NLS-1$

Check warning on line 169 in org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/ClasspathDescriptor.java

View check run for this annotation

Jenkins - M2E / Compiler

Restriction

NORMAL: Discouraged access: The type 'Util' is not API (restriction on classpath entry '/home/jenkins/.m2/repository/p2/osgi/bundle/org.eclipse.jdt.core/3.44.0.v20251118-1842/org.eclipse.jdt.core-3.44.0.v20251118-1842.jar')

Check warning on line 169 in org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/ClasspathDescriptor.java

View check run for this annotation

Jenkins - M2E / Compiler

Restriction

NORMAL: Discouraged access: The method 'Util.isExcluded(IPath, char[][], char[][], boolean)' is not API (restriction on classpath entry '/home/jenkins/.m2/repository/p2/osgi/bundle/org.eclipse.jdt.core/3.44.0.v20251118-1842/org.eclipse.jdt.core-3.44.0.v20251118-1842.jar')
inclusionPatterns = ((ClasspathEntry) otherEntry).fullInclusionPatternChars(),

Check warning on line 170 in org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/ClasspathDescriptor.java

View check run for this annotation

Jenkins - M2E / Compiler

Restriction

NORMAL: Discouraged access: The type 'ClasspathEntry' is not API (restriction on classpath entry '/home/jenkins/.m2/repository/p2/osgi/bundle/org.eclipse.jdt.core/3.44.0.v20251118-1842/org.eclipse.jdt.core-3.44.0.v20251118-1842.jar')

Check warning on line 170 in org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/ClasspathDescriptor.java

View check run for this annotation

Jenkins - M2E / Compiler

Restriction

NORMAL: Discouraged access: The method 'ClasspathEntry.fullInclusionPatternChars()' is not API (restriction on classpath entry '/home/jenkins/.m2/repository/p2/osgi/bundle/org.eclipse.jdt.core/3.44.0.v20251118-1842/org.eclipse.jdt.core-3.44.0.v20251118-1842.jar')
exclusionPatterns = ((ClasspathEntry) otherEntry).fullExclusionPatternChars(), false)) {

Check warning on line 171 in org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/ClasspathDescriptor.java

View check run for this annotation

Jenkins - M2E / Compiler

Restriction

NORMAL: Discouraged access: The type 'ClasspathEntry' is not API (restriction on classpath entry '/home/jenkins/.m2/repository/p2/osgi/bundle/org.eclipse.jdt.core/3.44.0.v20251118-1842/org.eclipse.jdt.core-3.44.0.v20251118-1842.jar')

Check warning on line 171 in org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/ClasspathDescriptor.java

View check run for this annotation

Jenkins - M2E / Compiler

Restriction

NORMAL: Discouraged access: The method 'ClasspathEntry.fullExclusionPatternChars()' is not API (restriction on classpath entry '/home/jenkins/.m2/repository/p2/osgi/bundle/org.eclipse.jdt.core/3.44.0.v20251118-1842/org.eclipse.jdt.core-3.44.0.v20251118-1842.jar')
String exclusionPattern = entryPath.removeFirstSegments(otherPath.segmentCount()).segment(0);

Check warning on line 172 in org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/ClasspathDescriptor.java

View check run for this annotation

Jenkins - M2E / Compiler

Unnecessary Code

NORMAL: The value of the local variable exclusionPattern is not used
if(!Util.isExcluded(entryPath, inclusionPatterns, exclusionPatterns, false)) {

Check warning on line 173 in org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/ClasspathDescriptor.java

View check run for this annotation

Jenkins - M2E / Compiler

Restriction

NORMAL: Discouraged access: The type 'Util' is not API (restriction on classpath entry '/home/jenkins/.m2/repository/p2/osgi/bundle/org.eclipse.jdt.core/3.44.0.v20251118-1842/org.eclipse.jdt.core-3.44.0.v20251118-1842.jar')

Check warning on line 173 in org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/ClasspathDescriptor.java

View check run for this annotation

Jenkins - M2E / Compiler

Restriction

NORMAL: Discouraged access: The method 'Util.isExcluded(IPath, char[][], char[][], boolean)' is not API (restriction on classpath entry '/home/jenkins/.m2/repository/p2/osgi/bundle/org.eclipse.jdt.core/3.44.0.v20251118-1842/org.eclipse.jdt.core-3.44.0.v20251118-1842.jar')
IPath[] newExclusions;
IPath[] oldExclusions = otherEntry.getExclusionPatterns();
if(otherEntry.getExclusionPatterns() == null)
newExclusions = new IPath[2];
else {
newExclusions = new IPath[oldExclusions.length + 2];
System.arraycopy(oldExclusions, 0, newExclusions, 0, oldExclusions.length);
}
IPath path = entryPath.removeFirstSegments(otherPath.segmentCount()).addTrailingSeparator();
IPath projectRelativePath = entryPath.removeFirstSegments(1).addTrailingSeparator();
newExclusions[newExclusions.length - 1] = projectRelativePath;
newExclusions[newExclusions.length - 2] = path;
if(toRemove == null || toAdd == null) {
toRemove = new ArrayList<>();
toAdd = new ArrayList<>();
}
IClasspathEntry newOtherEntry = JavaCore.newSourceEntry(otherEntry.getPath(),
otherEntry.getInclusionPatterns(), newExclusions, otherEntry.getOutputLocation(),
otherEntry.getExtraAttributes());
toRemove.add(otherEntry);
toAdd.add(newOtherEntry);
}
}
}
}
}
}
if(toRemove != null) {
toRemove.stream().forEach(e -> result.remove(e));
}
if(toAdd != null) {
toAdd.stream().forEach(e -> result.add(e));
}
return result.toArray(new IClasspathEntry[result.size()]);
}

Expand Down
Loading