-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2081 from jherkel/master
[2054] fix OSGI support (manifest, class loading)
- Loading branch information
Showing
6 changed files
with
289 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
108 changes: 108 additions & 0 deletions
108
liquibase-core/src/main/java/liquibase/osgi/Activator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
package liquibase.osgi; | ||
|
||
import java.util.Arrays; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.concurrent.CopyOnWriteArrayList; | ||
import liquibase.osgi.Activator.LiquibaseBundle; | ||
import org.osgi.framework.Bundle; | ||
import org.osgi.framework.BundleActivator; | ||
import org.osgi.framework.BundleContext; | ||
import org.osgi.framework.BundleEvent; | ||
import org.osgi.util.tracker.BundleTracker; | ||
import org.osgi.util.tracker.BundleTrackerCustomizer; | ||
|
||
public class Activator implements BundleActivator, BundleTrackerCustomizer<LiquibaseBundle> { | ||
|
||
private static final String LIQUIBASE_CUSTOM_CHANGE_WRAPPER_PACKAGES = "Liquibase-Custom-Change-Packages"; | ||
private BundleTracker<LiquibaseBundle> bundleTracker; | ||
private static final List<LiquibaseBundle> liquibaseBundles = new CopyOnWriteArrayList<>(); | ||
|
||
@Override | ||
public void start(final BundleContext bc) throws Exception { | ||
OSGIContainerChecker.osgiPlatform(); | ||
bundleTracker = new BundleTracker<>(bc, Bundle.ACTIVE, this); | ||
bundleTracker.open(); | ||
} | ||
|
||
@Override | ||
public void stop(BundleContext context) throws Exception { | ||
bundleTracker.close(); | ||
liquibaseBundles.clear(); | ||
} | ||
|
||
public static List<LiquibaseBundle> getLiquibaseBundles() { | ||
return Collections.unmodifiableList(liquibaseBundles); | ||
} | ||
|
||
@Override | ||
public LiquibaseBundle addingBundle(Bundle bundle, BundleEvent event) { | ||
if (bundle.getBundleId() == 0) { | ||
return null; | ||
} | ||
String customWrapperPackages = (String) bundle.getHeaders().get(LIQUIBASE_CUSTOM_CHANGE_WRAPPER_PACKAGES); | ||
if (customWrapperPackages != null) { | ||
LiquibaseBundle lb = new LiquibaseBundle(bundle, customWrapperPackages); | ||
liquibaseBundles.add(lb); | ||
return lb; | ||
} | ||
return null; | ||
} | ||
|
||
@Override | ||
public void modifiedBundle(Bundle bundle, BundleEvent event, LiquibaseBundle liquibaseBundle) { | ||
// nothing to do | ||
} | ||
|
||
@Override | ||
public void removedBundle(Bundle bundle, BundleEvent event, LiquibaseBundle liquibaseBundle) { | ||
if (liquibaseBundle != null) { | ||
liquibaseBundles.remove(liquibaseBundle); | ||
} | ||
} | ||
|
||
public static class LiquibaseBundle { | ||
|
||
private final Bundle bundle; | ||
private final List<String> allowedPackages; | ||
|
||
public LiquibaseBundle(Bundle bundle, String allowedPackages) { | ||
if (bundle == null) { | ||
throw new IllegalArgumentException("bundle cannot be empty"); | ||
} | ||
if (allowedPackages == null || allowedPackages.isEmpty()) { | ||
throw new IllegalArgumentException("packages cannot be empty"); | ||
} | ||
this.bundle = bundle; | ||
this.allowedPackages = Collections.unmodifiableList(Arrays.asList(allowedPackages.split(","))); | ||
} | ||
|
||
public Bundle getBundle() { | ||
return bundle; | ||
} | ||
|
||
public boolean allowedAllPackages() { | ||
return allowedPackages.size() == 1 | ||
&& "*".equals(allowedPackages.get(0)); | ||
} | ||
|
||
public List<String> getAllowedPackages() { | ||
return allowedPackages; | ||
} | ||
|
||
} | ||
|
||
public static class OSGIContainerChecker { | ||
|
||
private static volatile boolean osgiPlatform = false; | ||
|
||
public static boolean isOsgiPlatform() { | ||
return osgiPlatform; | ||
} | ||
|
||
static void osgiPlatform() { | ||
osgiPlatform = true; | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.