Skip to content

Commit

Permalink
Merge fe6a081 into da8ce63
Browse files Browse the repository at this point in the history
  • Loading branch information
royteeuwen committed May 11, 2017
2 parents da8ce63 + fe6a081 commit 3457712
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public class InjectorConfig {

private final String name;

private final String applicationPath;
private final List<String> applicationPaths;

private final String parentName;

Expand All @@ -57,14 +57,20 @@ public class InjectorConfig {
// we don't allow to change the module list after creating the configuration
modules = Collections.unmodifiableList(new ArrayList<Module>(runner.getModules()));
name = runner.getInjectorName();
applicationPath = StringUtils.defaultIfEmpty(runner.getApplicationPath(), DEFAULT_INJECTOR_PATH
+ name);
applicationPaths = getApplicationPaths(runner);
parentName = runner.getParentName();
basePackage = runner.getBasePackage();
bundleFilter = runner.getBundleNameFilter();
listener = runner;
}

private List<String> getApplicationPaths(InjectorRunner runner) {
if (runner.getApplicationPaths() == null){
return Collections.singletonList(DEFAULT_INJECTOR_PATH + name);
}
return runner.getApplicationPaths();
}

public String getName() {
return name;
}
Expand All @@ -89,8 +95,19 @@ public String getBundleNameFilter() {
return bundleFilter;
}

/**
* @deprecated The application path is made multi value, please use ${@link #getApplicationPaths()} from now on.
*/
@Deprecated
public String getApplicationPath() {
return applicationPath;
if(!applicationPaths.isEmpty()) {
return applicationPaths.get(0);
}
return null;
}

public List<String> getApplicationPaths() {
return applicationPaths;
}

public InjectorCreationFailListener getListener() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
package com.cognifide.slice.api.injector;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Dictionary;
import java.util.Hashtable;
import java.util.List;
Expand Down Expand Up @@ -79,7 +80,7 @@ public class InjectorRunner implements InjectorCreationFailListener {

private String parentInjectorName;

private String applicationPath;
private List<String> applicationPaths;

private boolean injectorCreationSuccess = true;

Expand All @@ -93,7 +94,20 @@ public class InjectorRunner implements InjectorCreationFailListener {
public InjectorRunner(final BundleContext bundleContext, final String injectorName,
final String applicationPath, final String bundleNameFilter, final String basePackage) {
this(bundleContext, injectorName, bundleNameFilter, basePackage);
this.applicationPath = applicationPath;
this.applicationPaths = Collections.singletonList(applicationPath);
}

/**
* @param bundleContext Context used to get access to the OSGi
* @param injectorName Name of the new injector
* @param applicationPaths paths to the application, e.g. {"/apps/myapp1", "/apps/myapp2"}
* @param bundleNameFilter filter used to scan bundles
* @param basePackage base package for classes to be scanned
*/
public InjectorRunner(final BundleContext bundleContext, final String injectorName,
final List<String> applicationPaths, final String bundleNameFilter, final String basePackage) {
this(bundleContext, injectorName, bundleNameFilter, basePackage);
this.applicationPaths = applicationPaths;
}

/**
Expand Down Expand Up @@ -178,7 +192,7 @@ String getParentName() {
return parentInjectorName;
}

String getApplicationPath() {
return applicationPath;
List<String> getApplicationPaths() {
return applicationPaths;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* limitations under the License.
* #L%
*/
@Version("4.2.0")
@Version("4.3.0")
package com.cognifide.slice.api.injector;

import aQute.bnd.annotation.Version;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,9 @@ private void refreshNameLookupMap() {
private void refreshNamesByPathMap() {
Map<String, String> map = new HashMap<String, String>();
for (Entry<String, InjectorConfig> entry : configByName.entrySet()) {
map.put(entry.getValue().getApplicationPath(), entry.getKey());
for (String applicationPath: entry.getValue().getApplicationPaths()) {
map.put(applicationPath, entry.getKey());
}
}
namesByPath = map;
}
Expand Down

0 comments on commit 3457712

Please sign in to comment.