Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JBIDE-18186 - support for module-alias in modules.xml inside wildfly/eap #263

Merged
merged 1 commit into from Aug 29, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -0,0 +1,42 @@
/*******************************************************************************
* Copyright (c) 2014 Red Hat, Inc.
* Distributed under license by Red Hat, Inc. All rights reserved.
* This program is made available under the terms of the
* Eclipse Public License v1.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Red Hat, Inc. - initial API and implementation
******************************************************************************/
package org.jboss.ide.eclipse.as.classpath.core.runtime.cache.internal;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;

import org.jboss.ide.eclipse.as.core.util.FileUtil;
import org.jboss.tools.foundation.core.xml.XMLMemento;

public class ModuleAliasUtil {
public String getAlias(File moduleXml) {
if( moduleXml.exists()) {
try {
String contents = FileUtil.getContents(moduleXml);
if( contents != null ) {
XMLMemento memento = XMLMemento.createReadRoot(new FileInputStream(moduleXml));
if( memento != null ) {
String nodeName = memento.getNodeName();
if( "module-alias".equals(nodeName)) {
String targName = memento.getString("target-name");
if( targName != null )
return targName;
}
}
}
} catch(IOException ce) {
// Ignore
}
}
return null;
}
}
Expand Up @@ -71,21 +71,30 @@ public IPath[] getJars(IPath modulesFolder) {
IPath lay = new Path(layeredPaths[i].getAbsolutePath());
File layeredPath = new File(lay.append(getPath()).toOSString());
if( layeredPath.exists()) {
return getJarsFrom(layeredPath);
return getJarsFrom(layeredPath, modulesFolder);
}
}
return new IPath[0];
}


private IPath[] getJarsFrom(File layeredPath) {
private IPath[] getJarsFrom(File layeredPath, IPath modulesFolder) {
ArrayList<IPath> list = new ArrayList<IPath>();
File[] children = layeredPath.listFiles();
for( int i = 0; i < children.length; i++ ) {
if( children[i].isFile() && children[i].getName().endsWith(".jar")) {
list.add(new Path(children[i].getAbsolutePath()));
}
}
if( list.size() == 0 ) {
// Odds are high this is a module-alias, so we should check.
File modulexml = new File(layeredPath, "module.xml");
String alias = new ModuleAliasUtil().getAlias(modulexml);
if( alias != null ) {
return new ModuleSlot(alias).getJars(modulesFolder);
Copy link
Member

Choose a reason for hiding this comment

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

what happens if this alias points to a chain of module alias to the same folder ? this would be an endless loop....too arcance to think it will happen ?

Copy link
Member Author

Choose a reason for hiding this comment

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

It definitely could happen, though it'd represent a broken installation and probably not happen often at all ;) I can work on adding more careful checking for cr2 to detect loops...

}
}

return (IPath[]) list.toArray(new IPath[list.size()]);
}
}