domaframework / doma-tools

Doma Tools
1 stars 1 forks source link

Exception thrown for multimodule maven projects #1

Open agentgt opened 5 years ago

agentgt commented 5 years ago

Doma Tools causes Eclipse to throw an exception for multimodule maven projects.

The issue is that multimodule maven projects often have a parent project that is NOT a Java project.

e.g. directory structure:

xyz-parent (pom project)
    xyz-java-project (java project)

For m2e to work both projects need to be imported.

The resource listener incorrectly assumes the Parent POM project (parent project w/ modules) into a Java Project (Java Nature).

    public DaoMethod createDaoMethod(IFile file) {
        AssertionUtil.assertNotNull(file);

        IJavaProject javaProject = JavaCore.create(file.getProject());
        if (javaProject == null) {
            return null;
        }

I guess JavaCore.create will happily turn any project into a Java project even if it isn't.

Below is the exception:

!ENTRY org.seasar.doma.extension.domax 4 0 2019-08-08 07:21:51.400
!MESSAGE
!STACK 1
Java Model Exception: Java Model Status [xyz-parent does not exist]
        at org.eclipse.jdt.internal.core.JavaElement.newNotPresentException(JavaElement.java:573)
        at org.eclipse.jdt.internal.core.JavaModelManager.getPerProjectInfoCheckExistence(JavaModelManager.java:2525)
        at org.eclipse.jdt.internal.core.JavaProject.getPerProjectInfo(JavaProject.java:2336)
        at org.eclipse.jdt.internal.core.JavaProject.getResolvedClasspath(JavaProject.java:2395)
        at org.eclipse.jdt.internal.core.JavaProject.getAllPackageFragmentRoots(JavaProject.java:1819)
        at org.eclipse.jdt.internal.core.JavaProject.getAllPackageFragmentRoots(JavaProject.java:1810)
        at org.seasar.doma.extension.domax.util.JavaProjectUtil.getSourceFolders(JavaProjectUtil.java:33)
        at org.seasar.doma.extension.domax.model.DaoMethodFactory.createDaoMethod(DaoMethodFactory.java:43)
        at org.seasar.doma.extension.domax.ResourceFileChangeListener.createDaoMethod(ResourceFileChangeListener.java:87)
        at org.seasar.doma.extension.domax.ResourceFileChangeListener.access$0(ResourceFileChangeListener.java:77)
        at org.seasar.doma.extension.domax.ResourceFileChangeListener$SqlFileDeltaVisitor.visit(ResourceFileChangeListener.java:67)
        at org.eclipse.core.internal.events.ResourceDelta.accept(ResourceDelta.java:67)
        at org.eclipse.core.internal.events.ResourceDelta.accept(ResourceDelta.java:77)
        at org.eclipse.core.internal.events.ResourceDelta.accept(ResourceDelta.java:77)
        at org.eclipse.core.internal.events.ResourceDelta.accept(ResourceDelta.java:77)
        at org.eclipse.core.internal.events.ResourceDelta.accept(ResourceDelta.java:77)
        at org.eclipse.core.internal.events.ResourceDelta.accept(ResourceDelta.java:77)
        at org.eclipse.core.internal.events.ResourceDelta.accept(ResourceDelta.java:77)
        at org.eclipse.core.internal.events.ResourceDelta.accept(ResourceDelta.java:77)
        at org.eclipse.core.internal.events.ResourceDelta.accept(ResourceDelta.java:77)
        at org.eclipse.core.internal.events.ResourceDelta.accept(ResourceDelta.java:77)
        at org.eclipse.core.internal.events.ResourceDelta.accept(ResourceDelta.java:77)
        at org.eclipse.core.internal.events.ResourceDelta.accept(ResourceDelta.java:77)
        at org.eclipse.core.internal.events.ResourceDelta.accept(ResourceDelta.java:77)
        at org.eclipse.core.internal.events.ResourceDelta.accept(ResourceDelta.java:51)
        at org.seasar.doma.extension.domax.ResourceFileChangeListener.resourceChanged(ResourceFileChangeListener.java:50)
        at org.eclipse.core.internal.events.NotificationManager$1.run(NotificationManager.java:305)
        at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:45)
        at org.eclipse.core.internal.events.NotificationManager.notify(NotificationManager.java:295)
        at org.eclipse.core.internal.events.NotificationManager.broadcastChanges(NotificationManager.java:158)
        at org.eclipse.core.internal.resources.Workspace.broadcastPostChange(Workspace.java:379)
        at org.eclipse.core.internal.resources.Workspace.aboutToBuild(Workspace.java:307)
        at org.eclipse.core.internal.resources.Project$1.run(Project.java:557)
        at org.eclipse.core.internal.resources.Workspace.run(Workspace.java:2295)
        at org.eclipse.core.internal.resources.Project.internalBuild(Project.java:540)
        at org.eclipse.core.internal.resources.Project.build(Project.java:116)
        at org.seasar.doma.extension.domax.ResourceFileChangeListener$1.runInWorkspace(ResourceFileChangeListener.java:114)
        at org.eclipse.core.internal.resources.InternalWorkspaceJob.run(InternalWorkspaceJob.java:42)
        at org.eclipse.core.internal.jobs.Worker.run(Worker.java:63)
agentgt commented 5 years ago

Per the Javadoc on JavaCore:

    /**
     * Returns the Java project corresponding to the given project.
     * <p>
     * Creating a Java Project has the side effect of creating and opening all of the
     * project's parents if they are not yet open.
     * <p>
     * Note that no check is done at this time on the existence or the java nature of this project.
     *
     * @param project the given project
     * @return the Java project corresponding to the given project, null if the given project is null
     */
    public static IJavaProject create(IProject project) {
        if (project == null) {
            return null;
        }
        JavaModel javaModel = JavaModelManager.getJavaModelManager().getJavaModel();
        return javaModel.getJavaProject(project);
    }

Notice:

Note that no check is done at this time on the existence or the java nature of this project.