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 enterprise/web.beans/nbproject/project.properties
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
# under the License.

javac.compilerargs=-Xlint -Xlint:-serial
javac.source=1.8
javac.release=21
requires.nb.javac=true

test-unit-sys-prop.java.awt.headless=true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
package org.netbeans.modules.web.beans.impl.model;

import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.concurrent.atomic.AtomicBoolean;

import javax.lang.model.element.Element;
Expand All @@ -42,42 +44,46 @@
*
*/
class PackagingFilter {


private final WebBeansModelImplementation myModel;

PackagingFilter(WebBeansModelImplementation model){
myModel = model;
}

void filter(Collection<? extends Element> collection, AtomicBoolean cancel ){
FilterContext context = new FilterContext();
for (Iterator<? extends Element> iterator = collection.iterator();
iterator.hasNext(); )
{
if(cancel.get()) {
break;
}
Element element = iterator.next();
if ( remove(element, cancel)){
if ( remove(element, context, cancel)){
iterator.remove();
}
}
}

void filterTypes(Collection<? extends DeclaredType> collection, AtomicBoolean cancel ){
FilterContext context = new FilterContext();
for (Iterator<? extends DeclaredType> iterator = collection.iterator();
iterator.hasNext(); )
{
DeclaredType type = iterator.next();
Element element = getModel().getHelper().getCompilationController().
getTypes().asElement( type );
if ( element != null && remove(element, cancel)){
if ( element != null && remove(element, context, cancel)){
iterator.remove();
}
}
}
private boolean remove( Element element, AtomicBoolean cancel ){

private boolean remove( Element element, FilterContext context, AtomicBoolean cancel ){
TypeElement typeElement;
if ( element instanceof TypeElement ){
typeElement = (TypeElement) element;
if ( element instanceof TypeElement te){
typeElement = te;
}
else {
typeElement = getModel().getHelper().getCompilationController().
Expand All @@ -86,15 +92,13 @@ private boolean remove( Element element, AtomicBoolean cancel ){
if ( typeElement == null || cancel.get()){
return false;
}

FileObject file = SourceUtils.getFile(ElementHandle.create(typeElement),
ClasspathInfo.create(getModel().getModelUnit().getBootPath() ,
ClassPath.EMPTY, getModel().getModelUnit().getSourcePath()));


FileObject file = SourceUtils.getFile(ElementHandle.create(typeElement), context.getCpInfo());

if ( file != null || cancel.get()){
return false;
}

PackageElement pack = getModel().getHelper().getCompilationController().
getElements().getPackageOf( typeElement );
if ( pack == null || cancel.get()){
Expand All @@ -116,7 +120,7 @@ private boolean remove( Element element, AtomicBoolean cancel ){
if ( className == null || cancel.get()){
return false;
}

String path = packageName.replace('.', '/')+'/'+className+".class"; // NOI18N
ClassPath classPath = getModel().getModelUnit().getCompilePath();
FileObject resource = classPath.findResource( path );
Expand All @@ -125,25 +129,41 @@ private boolean remove( Element element, AtomicBoolean cancel ){
if ( root == null || cancel.get()){
return false;
}
if ( FileUtil.isArchiveFile( root ) && !cancel.get()){
FileObject archiveFile = FileUtil.getArchiveFile(root);
String ext = archiveFile.getExt();
if ( "war".equalsIgnoreCase( ext)){ // NOI18N
return root.getFileObject("WEB-INF/beans.xml") == null; // NOI18N
return !context.hasBeansXml.computeIfAbsent(root, fo -> {
if (FileUtil.isArchiveFile(fo) && !cancel.get()) {
FileObject archiveFile = FileUtil.getArchiveFile(fo);
String ext = archiveFile.getExt();
if ("war".equalsIgnoreCase(ext)) { // NOI18N
return root.getFileObject("WEB-INF/beans.xml") != null; // NOI18N
}
}
}
return !hasMetaBeans(root);
return hasMetaBeans(fo);
});

}
return false;
}

private boolean hasMetaBeans(FileObject root ){
return root.getFileObject("META-INF/beans.xml") != null; // NOI18N
}

private WebBeansModelImplementation getModel(){
return myModel;
}

private WebBeansModelImplementation myModel;
private class FilterContext {

final Map<FileObject, Boolean> hasBeansXml = new HashMap<>();
private ClasspathInfo cpInfo;

ClasspathInfo getCpInfo() {
if (cpInfo == null) {
cpInfo = ClasspathInfo.create(getModel().getModelUnit().getBootPath(),
ClassPath.EMPTY, getModel().getModelUnit().getSourcePath());
}
return cpInfo;
}
}

}