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
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,14 @@

package org.netbeans.modules.web.api.webmodule;

import java.beans.PropertyChangeListener;
import java.util.Iterator;
import org.netbeans.api.j2ee.core.Profile;
import org.netbeans.api.project.FileOwnerQuery;
import org.netbeans.api.project.Project;
import org.netbeans.api.project.ProjectUtils;
import org.netbeans.api.project.SourceGroup;
import org.netbeans.api.project.Sources;
import org.netbeans.modules.j2ee.dd.api.web.WebAppMetadata;
import org.netbeans.modules.j2ee.metadata.model.api.MetadataModel;
import org.netbeans.modules.web.spi.webmodule.WebModuleImplementation;
Expand Down Expand Up @@ -103,17 +109,71 @@ private WebModule (WebModuleImplementation impl, WebModuleImplementation2 impl2)
* to any web module.
* @throws NullPointerException if the <code>file</code> parameter is null.
*/
public static WebModule getWebModule (FileObject file) {
public static WebModule getWebModule(FileObject file) {
Parameters.notNull("file", file); // NOI18N

Iterator<WebModuleProvider> it = implementations.allInstances().iterator();
while (it.hasNext()) {

WebModuleProvider impl = it.next();
WebModule wm = impl.findWebModule (file);
WebModule wm = impl.findWebModule(file);
if (wm != null) {
return wm;
}
}
return null;
final WebModule webModule = new WebModule(null, new WebModuleImplementation2() {
@Override
public FileObject getDocumentBase() {
Project project = FileOwnerQuery.getOwner(file);
Sources sources = ProjectUtils.getSources(project);
for (SourceGroup group : sources.getSourceGroups("java")) {
FileObject root = group.getRootFolder();
if (file.getPath().startsWith(root.getPath())) {
return root; // нашли src-папку, к которой относится файл
}
}
return project.getProjectDirectory();
}

@Override
public String getContextPath() {
return "/";
}

@Override
public Profile getJ2eeProfile() {
return Profile.JAVA_EE_8_FULL;
}

@Override
public FileObject getWebInf() {
return null;
}

@Override
public FileObject getDeploymentDescriptor() {
return null;
}

@Override
public FileObject[] getJavaSources() {
return new FileObject[0];
}

@Override
public MetadataModel<WebAppMetadata> getMetadataModel() {
return null;
}

@Override
public void addPropertyChangeListener(PropertyChangeListener listener) {
}

@Override
public void removePropertyChangeListener(PropertyChangeListener listener) {
}
});
return webModule;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,13 @@
import java.io.IOException;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.Callable;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicReference;
import javax.lang.model.element.TypeElement;
import javax.servlet.jsp.tagext.TagFileInfo;
import javax.servlet.jsp.tagext.TagInfo;
import javax.servlet.jsp.tagext.TagLibraryInfo;
import javax.swing.text.BadLocationException;
import javax.swing.text.Document;
import javax.swing.text.JTextComponent;
Expand All @@ -45,9 +47,6 @@
import org.netbeans.editor.BaseDocument;
import org.netbeans.editor.Utilities;
import org.netbeans.lib.editor.hyperlink.spi.HyperlinkProvider;
import org.netbeans.modules.web.jsps.parserapi.TagFileInfo;
import org.netbeans.modules.web.jsps.parserapi.TagInfo;
import org.netbeans.modules.web.jsps.parserapi.TagLibraryInfo;
import org.openide.awt.StatusDisplayer;
import org.openide.cookies.EditCookie;
import org.openide.filesystems.FileObject;
Expand Down Expand Up @@ -122,6 +121,12 @@ public void run() {
result.set(containsAttribute(tokenSequence, "file"));
} else if ("page".equals(sed.getName())) {
result.set(containsAttribute(tokenSequence, "errorPage"));

while (tokenSequence.moveNext() && tokenSequence.token().id() != JspTokenId.TAG) {
if (tokenSequence.token().id() == JspTokenId.ATTR_VALUE) {
result.set(true);
}
}
}
return;
}
Expand Down Expand Up @@ -416,11 +421,11 @@ public void run() {
Phase.ELEMENTS_RESOLVED,
new Worker<TypeElement>() {

@Override
public TypeElement process(CompilationInfo info) {
return info.getElements().getTypeElement(className);
}
});
@Override
public TypeElement process(CompilationInfo info) {
return info.getElements().getTypeElement(className);
}
});

ProgressUtils.runOffEventDispatchThread(compute,
NbBundle.getMessage(JspHyperlinkProvider.class, "MSG_goto-source"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,12 @@ public static WebCompositePanelProvider createWebServicesCategory() {
public static ProjectCustomizer.CompositeCategoryProvider createCssPreprocessors() {
return CssPreprocessorsUI.getDefault().createCustomizer();
}

@ProjectCustomizer.CompositeCategoryProvider.Registration(
projectType = "org-netbeans-modules-java-j2seproject", position = 500)
public static ProjectCustomizer.CompositeCategoryProvider createCssPreprocessorsj2se() {
return CssPreprocessorsUI.getDefault().createCustomizer();
}

@ProjectCustomizer.CompositeCategoryProvider.Registration(
projectType="org-netbeans-modules-web-project",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,9 @@ private static String processCompilerOptions(String compilerOptions, @NullAllowe
public static FileObject getWebRoot(Project project, FileObject fileObject) {
ProjectWebRootProvider projectWebRootProvider = getProjectWebRootProvider(project);
if (projectWebRootProvider == null) {
if (projectWebRootProvider == null) {
return project.getProjectDirectory();
}
return null;
}
return projectWebRootProvider.getWebRoot(fileObject);
Expand All @@ -153,7 +156,7 @@ public static FileObject getWebRoot(Project project, FileObject fileObject) {
public static FileObject getWebRoot(Project project) {
ProjectWebRootProvider projectWebRootProvider = getProjectWebRootProvider(project);
if (projectWebRootProvider == null) {
return null;
return project.getProjectDirectory();
}
Collection<FileObject> webRoots = projectWebRootProvider.getWebRoots();
if (webRoots.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,14 +111,14 @@
import org.openide.util.RequestProcessor;
import org.openide.util.TopologicalSortException;
import org.openide.util.Union2;
import org.openide.util.lookup.ServiceProvider;

import static org.netbeans.modules.parsing.impl.indexing.Debug.printCollection;
import static org.netbeans.modules.parsing.impl.indexing.Debug.printMap;
import static org.netbeans.modules.parsing.impl.indexing.Debug.printMimeTypes;
import org.netbeans.modules.parsing.impl.indexing.implspi.CacheFolderProvider;
import org.netbeans.modules.parsing.impl.indexing.implspi.ContextProvider;
import org.openide.util.lookup.Lookups;
import org.openide.util.lookup.ServiceProvider;
import org.openide.util.lookup.ServiceProviders;
/**
*
Expand Down Expand Up @@ -1316,6 +1316,7 @@ public void atomicUnlock(AtomicLockEvent e) {
private final Task worker;

private RepositoryUpdater () {
// LOGGER.setLevel(Level.ALL);
LOGGER.log(Level.FINE, "netbeans.indexing.notInterruptible={0}", NOT_INTERRUPTIBLE); //NOI18N
LOGGER.log(Level.FINE, "netbeans.indexing.recursiveListeners={0}", rootsListeners.hasRecursiveListeners()); //NOI18N
LOGGER.log(Level.FINE, "FILE_LOCKS_DELAY={0}", FILE_LOCKS_DELAY); //NOI18N
Expand Down Expand Up @@ -5953,8 +5954,7 @@ public void schedule (Work work, boolean wait) {
}

followUpWorksSorted = false;

if (!scheduled && (protectedOwners.isEmpty() || offProtectedMode == Thread.currentThread())) {
if (!scheduled && (isEmptyProtectedOwners() || offProtectedMode == Thread.currentThread())) {
scheduled = true;
LOGGER.fine("scheduled = true"); //NOI18N
WORKER.submit(this);
Expand All @@ -5968,6 +5968,11 @@ public void schedule (Work work, boolean wait) {
}
}

public boolean isEmptyProtectedOwners() {
protectedOwners.removeIf(Objects::isNull);
return protectedOwners.isEmpty();
}

void cancelAll(@NullAllowed final Runnable postCleanTask) throws TimeoutException {
synchronized (todo) {
if (!allCancelled) {
Expand Down Expand Up @@ -6030,7 +6035,7 @@ public void enterProtectedMode(@NullAllowed Long id) {

public void exitProtectedMode(@NullAllowed Long id, @NullAllowed Runnable followupTask) {
synchronized (todo) {
if (protectedOwners.isEmpty()) {
if (isEmptyProtectedOwners()) {
throw new IllegalStateException("Calling exitProtectedMode without enterProtectedMode"); //NOI18N
}

Expand All @@ -6046,7 +6051,7 @@ public void exitProtectedMode(@NullAllowed Long id, @NullAllowed Runnable follow
LOGGER.log(Level.FINE, "Exiting protected mode: {0}", protectedOwners.toString()); //NOI18N
}

if (protectedOwners.isEmpty()) {
if (isEmptyProtectedOwners()) {
// in normal mode again, restart all delayed jobs
final List<Runnable> tasks = followupTasks != null ? followupTasks : Collections.<Runnable>emptyList();
followupTasks = null;
Expand All @@ -6072,7 +6077,7 @@ <T> T runOffProtecedMode(@NonNull final Callable<T> call) throws Exception {

public boolean isInProtectedMode() {
synchronized (todo) {
return !protectedOwners.isEmpty();
return !isEmptyProtectedOwners();
}
}

Expand Down Expand Up @@ -6116,7 +6121,7 @@ public Void call() throws Exception {
RunWhenScanFinishedSupport.performScan(() -> _run(), globalLookup);
} finally {
synchronized (todo) {
if ((!protectedOwners.isEmpty() && offProtectedMode == null) || todo.isEmpty()) {
if ((!isEmptyProtectedOwners() && offProtectedMode == null) || todo.isEmpty()) {
scheduled = false;
LOGGER.fine("scheduled = false"); //NOI18N
} else {
Expand Down Expand Up @@ -6226,7 +6231,7 @@ private void _run() {
private Work getWork () {
synchronized (todo) {
Work w;
if ((protectedOwners.isEmpty() || offProtectedMode != null) && !todo.isEmpty()) {
if ((isEmptyProtectedOwners() || offProtectedMode != null) && !todo.isEmpty()) {
w = todo.remove(0);

if (w instanceof FileListWork && ((FileListWork) w).isFollowUpJob() && !followUpWorksSorted) {
Expand Down Expand Up @@ -6514,12 +6519,12 @@ public Controller() {

@Override
public void enterProtectedMode() {
worker.enterProtectedMode(Thread.currentThread().getId());
// worker.enterProtectedMode(Thread.currentThread().getId());
}

@Override
public void exitProtectedMode(Runnable followUpTask) {
worker.exitProtectedMode(Thread.currentThread().getId(), followUpTask);
// worker.exitProtectedMode(Thread.currentThread().getId(), followUpTask);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,20 @@
*/
package org.netbeans.modules.web.common.spi;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import org.netbeans.api.annotations.common.NonNull;
import org.netbeans.api.project.FileOwnerQuery;
import org.netbeans.api.project.Project;
import org.netbeans.api.project.ProjectUtils;
import org.netbeans.api.project.SourceGroup;
import org.netbeans.api.project.Sources;
import org.openide.filesystems.FileObject;
import org.openide.util.Parameters;

/**
* Clients uses this class to obtain a web root for a file within a web-like project.
* Clients uses this class to obtain a web root for a file within a web-like project.
*
* @author marekfukala
*/
Expand All @@ -52,7 +56,7 @@ public static FileObject getWebRoot(FileObject file) {
ProjectWebRootProvider provider = project.getLookup().lookup(ProjectWebRootProvider.class);
if (provider != null) {
FileObject root = provider.getWebRoot(file);
if(root == null) {
if (root == null) {
return null;
}

Expand All @@ -67,14 +71,22 @@ public static FileObject getWebRoot(FileObject file) {
*
* @param project a project which you want to get web roots for
* @return collection of web roots of the given project, can be empty but never {@code null}
*
* @since 1.57
*/
@NonNull
public static Collection<FileObject> getWebRoots(@NonNull Project project) {
Parameters.notNull("project", project); // NOI18N
ProjectWebRootProvider provider = project.getLookup().lookup(ProjectWebRootProvider.class);
if (provider == null) {
return Collections.emptyList();
List<FileObject> objects = new ArrayList<>();
Sources sources = ProjectUtils.getSources(project);
for (SourceGroup group : sources.getSourceGroups("java")) {
FileObject root = group.getRootFolder();
objects.add(root);
}
objects.add(project.getProjectDirectory());

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: blank line before the return?

return objects;
}
Collection<FileObject> webRoots = provider.getWebRoots();
assert webRoots != null : "WebRoots cannot be null in " + provider.getClass().getName();
Expand Down
Loading