org.jboss.forge.furnace.proxy.Proxies Java Examples

The following examples show how to use org.jboss.forge.furnace.proxy.Proxies. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: UICommands.java    From fabric8-forge with Apache License 2.0 6 votes vote down vote up
/**
 * Uses the given converter to convert to a nicer UI value and return the JSON safe version
 */
public static Object convertValueToSafeJson(Converter converter, Object value) {
    value = Proxies.unwrap(value);
    if (isJsonObject(value)) {
        return value;
    }
    if (converter != null) {
        // TODO converters ususally go from String -> CustomType?
        try {
            Object converted = converter.convert(value);
            if (converted != null) {
                value = converted;
            }
        } catch (Exception e) {
            // ignore - invalid converter
        }
    }
    if (value != null) {
        return toSafeJsonValue(value);
    } else {
        return null;
    }
}
 
Example #2
Source File: AbstractRuleProvider.java    From windup with Eclipse Public License 1.0 6 votes vote down vote up
public AbstractRuleProvider()
{
    /*
     * In the case of a proxy, the no-args constructor will be called. This is the case even if the provider
     * itself would normally have a metadata param passed in.
     *
     * Once completed, the getMetadata() method will be proxied correctly, so this is ok. Just allow it to pass
     * in this case.
     */
    if (Proxies.isForgeProxy(this) && !Annotations.isAnnotationPresent(getClass(), RuleMetadata.class))
        return;

    if (!Annotations.isAnnotationPresent(getClass(), RuleMetadata.class))
    {
        throw new IllegalStateException(getClass().getName() + " must either "
                    + "be abstract, or specify @" + RuleMetadata.class.getName()
                    + ", or call a super() constructor and provide " + RuleProviderMetadata.class.getName());
    }
    this.metadata = MetadataBuilder.forProvider(getClass());
}
 
Example #3
Source File: CLACProxiedIterableTest.java    From furnace with Eclipse Public License 1.0 6 votes vote down vote up
@Test
public void testIterableTypesAreProxied() throws Exception
{
   AddonRegistry registry = LocalServices.getFurnace(getClass().getClassLoader())
            .getAddonRegistry();
   ClassLoader thisLoader = CLACProxiedIterableTest.class.getClassLoader();
   ClassLoader dep1Loader = registry.getAddon(AddonId.from("dep", "1")).getClassLoader();

   Class<?> foreignType = dep1Loader.loadClass(IterableFactory.class.getName());
   Iterable<?> proxy = (Iterable<?>) foreignType.getMethod("getIterable")
            .invoke(foreignType.newInstance());
   Assert.assertFalse(Proxies.isForgeProxy(proxy));

   Object delegate = foreignType.newInstance();
   IterableFactory enhancedFactory = (IterableFactory) ClassLoaderAdapterBuilder.callingLoader(thisLoader)
            .delegateLoader(dep1Loader).enhance(delegate);

   Assert.assertTrue(Proxies.isForgeProxy(enhancedFactory));
   Iterable<?> enhancedInstance = enhancedFactory.getIterable();
   Assert.assertTrue(Proxies.isForgeProxy(enhancedInstance));

   Iterator<?> iterator = enhancedInstance.iterator();
   Assert.assertNotNull(iterator);
}
 
Example #4
Source File: RuleProviderHandler.java    From windup with Eclipse Public License 1.0 6 votes vote down vote up
private Map<String, Class<? extends RulePhase>> getPhases()
{
    if (cachedPhases == null)
    {
        cachedPhases = new HashMap<>();
        Furnace furnace = FurnaceHolder.getFurnace();
        for (RulePhase phase : furnace.getAddonRegistry().getServices(RulePhase.class))
        {
            @SuppressWarnings("unchecked")
            Class<? extends RulePhase> unwrappedClass = (Class<? extends RulePhase>) Proxies.unwrap(phase).getClass();
            String simpleName = unwrappedClass.getSimpleName();
            cachedPhases.put(classNameToKey(simpleName), unwrappedClass);
        }
    }
    return Collections.unmodifiableMap(cachedPhases);
}
 
Example #5
Source File: ParserContext.java    From windup with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Initialize tag handlers based upon the provided furnace instance.
 */
public ParserContext(Furnace furnace, RuleLoaderContext ruleLoaderContext)
{
    this.ruleLoaderContext = ruleLoaderContext;

    @SuppressWarnings("rawtypes")
    Imported<ElementHandler> loadedHandlers = furnace.getAddonRegistry().getServices(ElementHandler.class);
    for (ElementHandler<?> handler : loadedHandlers)
    {
        NamespaceElementHandler annotation = Annotations.getAnnotation(handler.getClass(),
                    NamespaceElementHandler.class);
        if (annotation != null)
        {
            HandlerId handlerID = new HandlerId(annotation.namespace(), annotation.elementName());
            if (handlers.containsKey(handlerID))
            {
                String className1 = Proxies.unwrapProxyClassName(handlers.get(handlerID).getClass());
                String className2 = Proxies.unwrapProxyClassName(handler.getClass());
                throw new WindupException("Multiple handlers registered with id: " + handlerID + " Classes are: "
                            + className1 + " and " + className2);
            }
            handlers.put(handlerID, handler);
        }
    }
}
 
Example #6
Source File: SystemClassLoaderNullClassLoaderAdapterTest.java    From furnace with Eclipse Public License 1.0 6 votes vote down vote up
@Test
@SuppressWarnings("unchecked")
public void testNullSystemClassLoaderDefaultsToFurnaceProxyCL() throws Exception
{
   ClassLoader thisLoader = SystemClassLoaderNullClassLoaderAdapterTest.class.getClassLoader();

   ClassLoader dep1Loader = new EmptyClassLoader();
   Class<?> foreignType = dep1Loader.loadClass(ArrayListFactory.class.getName());
   Object foreignInstance = foreignType.newInstance();
   List<?> proxy = (List<?>) foreignType.getMethod("getArrayList").invoke(foreignInstance);
   Assert.assertFalse(Proxies.isForgeProxy(proxy));

   Object delegate = foreignType.newInstance();
   ArrayListFactory enhancedFactory = (ArrayListFactory) ClassLoaderAdapterBuilder.callingLoader(thisLoader)
            .delegateLoader(dep1Loader).enhance(delegate);

   Assert.assertTrue(Proxies.isForgeProxy(enhancedFactory));

   @SuppressWarnings("rawtypes")
   List enhancedInstance = enhancedFactory.getArrayList();
   enhancedInstance.add(new ArrayListFactory());
   enhancedInstance.get(0);
   Assert.assertTrue(Proxies.isForgeProxy(enhancedInstance));

}
 
Example #7
Source File: RuleLoaderImpl.java    From windup with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Prints all of the {@link RulePhase} objects in the order that they should execute. This is primarily for debug purposes and should be called
 * before the entire {@link RuleProvider} list is sorted, as this will allow us to print the {@link RulePhase} list without the risk of
 * user-introduced cycles making the sort impossible.
 */
private void printRulePhases(List<RuleProvider> allProviders)
{
    List<RuleProvider> unsortedPhases = new ArrayList<>();
    for (RuleProvider provider : allProviders)
    {
        if (provider instanceof RulePhase)
            unsortedPhases.add(provider);
    }
    List<RuleProvider> sortedPhases = RuleProviderSorter.sort(unsortedPhases);
    StringBuilder rulePhaseSB = new StringBuilder();
    for (RuleProvider phase : sortedPhases)
    {
        Class<?> unproxiedClass = Proxies.unwrap(phase).getClass();
        rulePhaseSB.append("\tPhase: ").append(unproxiedClass.getSimpleName()).append(System.lineSeparator());
    }
    LOG.info("Rule Phases: [\n" + rulePhaseSB.toString() + "]");
}
 
Example #8
Source File: ClassLoaderAdapterJavaUtilLoggingTest.java    From furnace with Eclipse Public License 1.0 6 votes vote down vote up
@Test
public void testLogRecordProxy() throws Exception
{
    AddonRegistry registry = LocalServices.getFurnace(getClass().getClassLoader())
            .getAddonRegistry();
    ClassLoader thisLoader = ClassLoaderAdapterJavaUtilLoggingTest.class.getClassLoader();
    ClassLoader dep1Loader = registry.getAddon(AddonId.from("dep", "1")).getClassLoader();

    Class<?> foreignType = dep1Loader.loadClass(JavaUtilLoggingFactory.class.getName());
    LogRecord logRecord = (LogRecord) foreignType.getMethod("getLogRecord")
            .invoke(foreignType.newInstance());

    Assert.assertNotNull(logRecord);
    Assert.assertTrue(logRecord.getClass().equals(LogRecord.class));

    Object delegate = foreignType.newInstance();
    JavaUtilLoggingFactory enhancedFactory = (JavaUtilLoggingFactory) ClassLoaderAdapterBuilder.callingLoader(thisLoader)
            .delegateLoader(dep1Loader).enhance(delegate);

    Assert.assertTrue(Proxies.isForgeProxy(enhancedFactory));
    LogRecord result = enhancedFactory.getLogRecord();
    Assert.assertFalse(Proxies.isForgeProxy(result));
}
 
Example #9
Source File: ClassLoaderAdapterPassthroughTest.java    From furnace with Eclipse Public License 1.0 6 votes vote down vote up
@Test
public void testParameterPassthroughIfTypeIsShared() throws Exception
{
   AddonRegistry registry = LocalServices.getFurnace(getClass().getClassLoader())
            .getAddonRegistry();
   ClassLoader thisLoader = ClassLoaderAdapterPassthroughTest.class.getClassLoader();
   ClassLoader loader1 = registry.getAddon(AddonId.from("dep", "1")).getClassLoader();

   ClassWithGetterAndSetter local = new ClassWithGetterAndSetter();
   local.setPassthrough((ClassWithPassthroughMethod) loader1
            .loadClass(ClassWithPassthroughMethod.class.getName())
            .newInstance());

   Object delegate = loader1.loadClass(ClassWithGetterAndSetter.class.getName()).newInstance();
   ClassWithGetterAndSetter enhanced = (ClassWithGetterAndSetter) ClassLoaderAdapterBuilder
            .callingLoader(thisLoader).delegateLoader(loader1).enhance(delegate);

   enhanced.setPassthrough(new ClassWithPassthroughMethod());

   Assert.assertNotNull(enhanced);
   Assert.assertNotNull(enhanced.getPassthrough());
   Assert.assertFalse(Proxies.isForgeProxy(enhanced.getPassthrough()));
   Assert.assertFalse(enhanced.assertPassthroughNotProxied());
}
 
Example #10
Source File: CLACProxiedIterableTest.java    From furnace with Eclipse Public License 1.0 6 votes vote down vote up
@Test
public void testCustomIterableTypesAreProxied() throws Exception
{
   AddonRegistry registry = LocalServices.getFurnace(getClass().getClassLoader())
            .getAddonRegistry();
   ClassLoader thisLoader = CLACProxiedIterableTest.class.getClassLoader();
   ClassLoader dep1Loader = registry.getAddon(AddonId.from("dep", "1")).getClassLoader();

   Class<?> foreignType = dep1Loader.loadClass(IterableFactory.class.getName());
   Iterable<?> proxy = (Iterable<?>) foreignType.getMethod("getIterable")
            .invoke(foreignType.newInstance());
   Assert.assertFalse(Proxies.isForgeProxy(proxy));

   Object delegate = foreignType.newInstance();
   IterableFactory enhancedFactory = (IterableFactory) ClassLoaderAdapterBuilder.callingLoader(thisLoader)
            .delegateLoader(dep1Loader).enhance(delegate);

   Assert.assertTrue(Proxies.isForgeProxy(enhancedFactory));
   Iterable<?> enhancedInstance = enhancedFactory.getCustomIterable();
   Assert.assertTrue(Proxies.isForgeProxy(enhancedInstance));

   Iterator<?> iterator = enhancedInstance.iterator();
   Assert.assertNotNull(iterator);
}
 
Example #11
Source File: ClassLoaderAdapterJavaIOTest.java    From furnace with Eclipse Public License 1.0 6 votes vote down vote up
@Test
public void testSimpleFileProxy() throws Exception
{
   AddonRegistry registry = LocalServices.getFurnace(getClass().getClassLoader())
            .getAddonRegistry();
   ClassLoader thisLoader = ClassLoaderAdapterJavaIOTest.class.getClassLoader();
   ClassLoader dep1Loader = registry.getAddon(AddonId.from("dep", "1")).getClassLoader();

   Class<?> foreignType = dep1Loader.loadClass(JavaIOFactory.class.getName());
   File file = (File) foreignType.getMethod("getFile")
            .invoke(foreignType.newInstance());

   Assert.assertNotNull(file);
   Assert.assertTrue(file.getClass().equals(File.class));

   Object delegate = foreignType.newInstance();
   JavaIOFactory enhancedFactory = (JavaIOFactory) ClassLoaderAdapterBuilder.callingLoader(thisLoader)
            .delegateLoader(dep1Loader).enhance(delegate);

   Assert.assertTrue(Proxies.isForgeProxy(enhancedFactory));
   File result = enhancedFactory.getFile();
   Assert.assertFalse(Proxies.isForgeProxy(result));

   enhancedFactory.useFile(new File("foo"));
}
 
Example #12
Source File: ClassLoaderAdapterWhitelistLoaderPassthroughTest.java    From furnace with Eclipse Public License 1.0 6 votes vote down vote up
@Test
public void testProxyNotPropagatedIfClassLoadersBothInWhitelist() throws Exception
{
   AddonRegistry registry = LocalServices.getFurnace(getClass().getClassLoader())
            .getAddonRegistry();
   ClassLoader thisLoader = ClassLoaderAdapterWhitelistLoaderPassthroughTest.class.getClassLoader();
   ClassLoader loader1 = registry.getAddon(AddonId.from("dep1", "1")).getClassLoader();
   ClassLoader loader2 = registry.getAddon(AddonId.from("dep2", "1")).getClassLoader();
   ClassLoader loader3 = registry.getAddon(AddonId.from("dep3", "1")).getClassLoader();

   MockContext context = new MockContext();

   Object delegate = loader1.loadClass(MockContextConsumer.class.getName()).newInstance();
   MockContextConsumer enhancedConsumer = (MockContextConsumer) ClassLoaderAdapterBuilder
            .callingLoader(thisLoader).delegateLoader(loader1)
            .whitelist(new HashSet<>(Arrays.asList(loader1, loader2, loader3)))
            .enhance(delegate);

   Object payload = loader2.loadClass(MockContextPayloadImpl.class.getName()).newInstance();
   context.getAttributes().put(MockContextPayload.class.getName(), payload);

   enhancedConsumer.processContext(context);

   Object object = context.getAttributes().get(MockContextPayload.class.getName());
   Assert.assertFalse(Proxies.isForgeProxy(object));
}
 
Example #13
Source File: ProxiesTest.java    From furnace with Eclipse Public License 1.0 6 votes vote down vote up
@Test
public void testIsInstance()
{
   Bean enhancedObj = Proxies.enhance(Bean.class, new ForgeProxy()
   {

      @Override
      public Object invoke(Object self, Method thisMethod, Method proceed, Object[] args) throws Throwable
      {
         return proceed.invoke(self, args);
      }

      @Override
      public Object getDelegate() throws Exception
      {
         return null;
      }

      @Override
      public Object getHandler() throws Exception
      {
         return this;
      }
   });
   Assert.assertTrue(Proxies.isInstance(Bean.class, enhancedObj));
}
 
Example #14
Source File: ProxiesTest.java    From furnace with Eclipse Public License 1.0 6 votes vote down vote up
@Test
public void testIsLanguageType() throws Exception
{
   Assert.assertTrue(Proxies.isLanguageType(Object[].class));
   Assert.assertTrue(Proxies.isLanguageType(byte[].class));
   Assert.assertTrue(Proxies.isLanguageType(float[].class));
   Assert.assertTrue(Proxies.isLanguageType(char[].class));
   Assert.assertTrue(Proxies.isLanguageType(double[].class));
   Assert.assertTrue(Proxies.isLanguageType(int[].class));
   Assert.assertTrue(Proxies.isLanguageType(long[].class));
   Assert.assertTrue(Proxies.isLanguageType(short[].class));
   Assert.assertTrue(Proxies.isLanguageType(boolean[].class));
   Assert.assertTrue(Proxies.isLanguageType(Object.class));
   Assert.assertTrue(Proxies.isLanguageType(InputStream.class));
   Assert.assertTrue(Proxies.isLanguageType(Runnable.class));
   Assert.assertTrue(Proxies.isLanguageType(String.class));
   Assert.assertTrue(Proxies.isLanguageType(Class.class));
   Assert.assertTrue(Proxies.isLanguageType(ClassLoader.class));
   Assert.assertTrue(Proxies.isLanguageType(BigDecimal.class));
   Assert.assertTrue(Proxies.isLanguageType(List.class));
   Assert.assertTrue(Proxies.isLanguageType(Set.class));
   Assert.assertTrue(Proxies.isLanguageType(Iterable.class));
   Assert.assertTrue(Proxies.isLanguageType(Map.class));
}
 
Example #15
Source File: ProxiesTest.java    From furnace with Eclipse Public License 1.0 6 votes vote down vote up
@Test
public void testCertainLanguageTypesRequireProxying() throws Exception
{
   Assert.assertTrue(Proxies.isPassthroughType(Object[].class));
   Assert.assertTrue(Proxies.isPassthroughType(byte[].class));
   Assert.assertTrue(Proxies.isPassthroughType(float[].class));
   Assert.assertTrue(Proxies.isPassthroughType(char[].class));
   Assert.assertTrue(Proxies.isPassthroughType(double[].class));
   Assert.assertTrue(Proxies.isPassthroughType(int[].class));
   Assert.assertTrue(Proxies.isPassthroughType(long[].class));
   Assert.assertTrue(Proxies.isPassthroughType(short[].class));
   Assert.assertTrue(Proxies.isPassthroughType(boolean[].class));
   Assert.assertTrue(Proxies.isPassthroughType(Object.class));
   Assert.assertTrue(Proxies.isPassthroughType(InputStream.class));
   Assert.assertTrue(Proxies.isPassthroughType(Runnable.class));
   Assert.assertTrue(Proxies.isPassthroughType(String.class));
   Assert.assertTrue(Proxies.isPassthroughType(Class.class));
   Assert.assertTrue(Proxies.isPassthroughType(ClassLoader.class));
   Assert.assertFalse(Proxies.isPassthroughType(BigDecimal.class));
   Assert.assertFalse(Proxies.isPassthroughType(List.class));
   Assert.assertFalse(Proxies.isPassthroughType(Set.class));
   Assert.assertFalse(Proxies.isPassthroughType(Iterable.class));
   Assert.assertFalse(Proxies.isPassthroughType(Map.class));
}
 
Example #16
Source File: ProxiesTest.java    From furnace with Eclipse Public License 1.0 6 votes vote down vote up
@Test
public void testIsProxyObjectType() throws Exception
{
   Assert.assertTrue(Proxies.isProxyType(new ProxyObject()
   {
      @Override
      public void setHandler(MethodHandler mi)
      {
      }

      @Override
      public MethodHandler getHandler()
      {
         return null;
      }
   }.getClass()));
}
 
Example #17
Source File: ClassLoaderAdapterProxiedTest.java    From furnace with Eclipse Public License 1.0 6 votes vote down vote up
@Test
public void testShouldNotProxyJavaUtilLogging() throws Exception {
   ClassLoader loader = JavaUtilLoggingFactory.class.getClassLoader();
   final JavaUtilLoggingFactory internal = new JavaUtilLoggingFactory();

   JavaUtilLoggingFactory delegate = (JavaUtilLoggingFactory) Enhancer.create(JavaUtilLoggingFactory.class, new LazyLoader() {
      @Override
      public Object loadObject() throws Exception {
         return internal;
      }
   });

   JavaUtilLoggingFactory adapter = ClassLoaderAdapterBuilder.callingLoader(loader).delegateLoader(loader)
           .enhance(delegate, JavaUtilLoggingFactory.class);
   LogRecord logRecord = adapter.getLogRecord();
   Assert.assertFalse(Proxies.isProxyType(logRecord.getClass()));
   Assert.assertFalse(Proxies.isProxyType(logRecord.getLevel().getClass()));
}
 
Example #18
Source File: ClassLoaderAdapterProxiedTest.java    From furnace with Eclipse Public License 1.0 6 votes vote down vote up
@Test
public void testShouldNotProxyJavaNioPath() throws Exception
{
   ClassLoader loader = JavaIOFactory.class.getClassLoader();
   final JavaIOFactory internal = new JavaIOFactory();

   JavaIOFactory delegate = (JavaIOFactory) Enhancer.create(JavaIOFactory.class, new LazyLoader()
   {
      @Override
      public Object loadObject() throws Exception
      {
         return internal;
      }
   });
   JavaIOFactory adapter = ClassLoaderAdapterBuilder.callingLoader(loader).delegateLoader(loader)
            .enhance(delegate, JavaIOFactory.class);
   Path path = adapter.getPath();
   Assert.assertFalse(Proxies.isProxyType(path.getClass()));
}
 
Example #19
Source File: ClassLoaderAdapterProxiedTest.java    From furnace with Eclipse Public License 1.0 6 votes vote down vote up
@Test
public void testAdaptFinalResult() throws Exception
{
   ClassLoader loader = MockService.class.getClassLoader();
   final MockService internal = new MockService();

   MockService delegate = (MockService) Enhancer.create(MockService.class, new LazyLoader()
   {
      @Override
      public Object loadObject() throws Exception
      {
         return internal;
      }
   });

   MockService adapter = ClassLoaderAdapterBuilder.callingLoader(loader).delegateLoader(loader)
            .enhance(delegate, MockService.class);

   Assert.assertNotEquals(internal.getResultInterfaceFinalImpl(), adapter.getResultInterfaceFinalImpl());
   Object unwrapped = Proxies.unwrap(adapter);
   Assert.assertNotSame(adapter, unwrapped);
}
 
Example #20
Source File: CLACProxiedCollectionsTest.java    From furnace with Eclipse Public License 1.0 6 votes vote down vote up
@Test
public void testIterableTypesAreProxied() throws Exception
{
   AddonRegistry registry = LocalServices.getFurnace(getClass().getClassLoader())
            .getAddonRegistry();
   ClassLoader thisLoader = CLACProxiedCollectionsTest.class.getClassLoader();
   ClassLoader dep1Loader = registry.getAddon(AddonId.from("dep", "1")).getClassLoader();

   Class<?> foreignType = dep1Loader.loadClass(ProfileCommand.class.getName());

   Object delegate = foreignType.newInstance();
   ProfileCommand enhanced = (ProfileCommand) ClassLoaderAdapterBuilder.callingLoader(thisLoader)
            .delegateLoader(dep1Loader).enhance(delegate);

   ProfileManagerImpl manager = new ProfileManagerImpl();
   enhanced.setManager(manager);
   enhanced.configureProfile();
   Assert.assertTrue(Proxies.isForgeProxy(enhanced));
}
 
Example #21
Source File: ProxiesTest.java    From furnace with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void testEqualsAndHashCode()
{
   Bean bean1 = new Bean();
   String attributeValue = "String";
   bean1.setAtt(attributeValue);
   Bean enhancedObj = Proxies.enhance(Bean.class, new ClassLoaderInterceptor(Bean.class.getClassLoader(), bean1));
   enhancedObj.setAtt(attributeValue);

   Bean bean2 = new Bean();
   bean2.setAtt(attributeValue);

   Assert.assertTrue(enhancedObj.equals(bean2));
}
 
Example #22
Source File: LabelLoaderImpl.java    From windup with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Multiple 'Labelsets' with the same ID are not allowed. See {@link LabelsetMetadata#getID()}
 *
 * @throws WindupException in case there are multiple 'Labelsets' using the same ID
 **/
private void checkForDuplicateProviders(List<LabelProvider> providers)
{
    /*
     * LabelsetMetadata We are using a map so that we can easily pull out the previous value later (in the case of a duplicate)
     */
    Map<LabelProvider, LabelProvider> duplicates = new HashMap<>(providers.size());
    for (LabelProvider provider : providers)
    {
        LabelProvider previousProvider = duplicates.get(provider);
        if (previousProvider != null)
        {
            String typeMessage;
            String currentProviderOrigin = provider.getMetadata().getOrigin();
            String previousProviderOrigin = previousProvider.getMetadata().getOrigin();
            if (previousProvider.getClass().equals(provider.getClass()))
            {
                typeMessage = " (type: " + previousProviderOrigin + " and " + currentProviderOrigin + ")";
            }
            else
            {
                typeMessage = " (types: " + Proxies.unwrapProxyClassName(previousProvider.getClass()) + " at " + previousProviderOrigin
                            + " and " + Proxies.unwrapProxyClassName(provider.getClass()) + " at " + currentProviderOrigin + ")";
            }

            throw new WindupException("Found two providers with the same id: " + provider.getMetadata().getID() + typeMessage);
        }
        duplicates.put(provider, provider);
    }
}
 
Example #23
Source File: RuleLoaderImpl.java    From windup with Eclipse Public License 1.0 5 votes vote down vote up
private void checkForDuplicateProviders(List<RuleProvider> providers)
{
    /*
     * We are using a map so that we can easily pull out the previous value later (in the case of a duplicate)
     */
    Map<RuleProvider, RuleProvider> duplicates = new HashMap<>(providers.size());
    for (RuleProvider provider : providers)
    {
        RuleProvider previousProvider = duplicates.get(provider);
        if (previousProvider != null)
        {
            String typeMessage;
            String currentProviderOrigin = provider.getMetadata().getOrigin();
            String previousProviderOrigin = previousProvider.getMetadata().getOrigin();
            if (previousProvider.getClass().equals(provider.getClass()))
            {
                typeMessage = " (type: " + previousProviderOrigin + " and " + currentProviderOrigin + ")";
            }
            else
            {
                typeMessage = " (types: " + Proxies.unwrapProxyClassName(previousProvider.getClass()) + " at " + previousProviderOrigin
                            + " and " + Proxies.unwrapProxyClassName(provider.getClass()) + " at " + currentProviderOrigin + ")";
            }

            throw new WindupException("Found two providers with the same id: " + provider.getMetadata().getID() + typeMessage);
        }
        duplicates.put(provider, provider);
    }
}
 
Example #24
Source File: TagsIncludeExcludeTest.java    From windup with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public boolean beforeRuleEvaluation(GraphRewrite event, Rule rule, EvaluationContext context)
{
    RuleProvider provider = (RuleProvider) ((Context) rule).get(RuleMetadataType.RULE_PROVIDER);
    String realName = Proxies.unwrapProxyClassName(provider.getClass());
    executedRules.put(realName, Boolean.FALSE);
    return false;
}
 
Example #25
Source File: ProxiesTest.java    From furnace with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void testIsProxyType() throws Exception
{
   Assert.assertTrue(Proxies.isProxyType(new Proxy()
   {
      @Override
      public void setHandler(MethodHandler mi)
      {
      }
   }.getClass()));
}
 
Example #26
Source File: TagsIncludeExcludeTest.java    From windup with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void afterRuleConditionEvaluation(GraphRewrite event, EvaluationContext context, Rule rule, boolean result)
{
    RuleProvider provider = (RuleProvider) ((Context) rule).get(RuleMetadataType.RULE_PROVIDER);
    String realName = Proxies.unwrapProxyClassName(provider.getClass());
    executedRules.put(realName, Boolean.TRUE);
}
 
Example #27
Source File: SkippingReportsRenderingTest.java    From windup with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void afterRuleConditionEvaluation(GraphRewrite event, EvaluationContext context, Rule rule, boolean result)
{
    RuleProvider provider = (RuleProvider) ((Context) rule).get(RuleMetadataType.RULE_PROVIDER);
    String realName = Proxies.unwrapProxyClassName(provider.getClass());
    executedRules.put(realName, Boolean.TRUE);
}
 
Example #28
Source File: ProxiesTest.java    From furnace with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void testAreEquivalent()
{
   Bean enhancedObj = Proxies.enhance(Bean.class, new ForgeProxy()
   {

      @Override
      public Object invoke(Object self, Method thisMethod, Method proceed, Object[] args) throws Throwable
      {
         return proceed.invoke(self, args);
      }

      @Override
      public Object getDelegate()
      {
         return null;
      }

      @Override
      public Object getHandler() throws Exception
      {
         return this;
      }
   });
   enhancedObj.setAtt("String");
   Bean bean2 = new Bean();
   bean2.setAtt("String");

   Assert.assertTrue(Proxies.areEquivalent(enhancedObj, bean2));
}
 
Example #29
Source File: SkippingReportsRenderingTest.java    From windup with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public boolean beforeRuleEvaluation(GraphRewrite event, Rule rule, EvaluationContext context)
{
    RuleProvider provider = (RuleProvider) ((Context) rule).get(RuleMetadataType.RULE_PROVIDER);
    String realName = Proxies.unwrapProxyClassName(provider.getClass());
    executedRules.put(realName, Boolean.FALSE);
    return false;
}
 
Example #30
Source File: RulePhaseFinder.java    From windup with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Loads the currently known phases from Furnace to the map.
 */
private Map<String, Class<? extends RulePhase>> loadPhases()
{
    Map<String, Class<? extends RulePhase>> phases;
    phases = new HashMap<>();
    Furnace furnace = FurnaceHolder.getFurnace();
    for (RulePhase phase : furnace.getAddonRegistry().getServices(RulePhase.class))
    {
        @SuppressWarnings("unchecked")
        Class<? extends RulePhase> unwrappedClass = (Class<? extends RulePhase>) Proxies.unwrap(phase).getClass();
        String simpleName = unwrappedClass.getSimpleName();
        phases.put(classNameToMapKey(simpleName), unwrappedClass);
    }
    return Collections.unmodifiableMap(phases);
}