Search in sources :

Example 1 with ProviderNotFoundException

use of java.nio.file.ProviderNotFoundException in project j2objc by google.

the class FileSystemsTest method test_newFileSystem$URI$Map.

@Test
public void test_newFileSystem$URI$Map() throws IOException {
    Path testPath = Paths.get("/");
    Map<String, String> stubEnv = new HashMap<>();
    try {
        FileSystems.newFileSystem(testPath.toUri(), stubEnv);
        fail();
    } catch (FileSystemAlreadyExistsException expected) {
    }
    try {
        FileSystems.newFileSystem(null, stubEnv);
        fail();
    } catch (NullPointerException expected) {
    }
    try {
        FileSystems.newFileSystem(testPath, null);
        fail();
    } catch (ProviderNotFoundException expected) {
    }
}
Also used : Path(java.nio.file.Path) ProviderNotFoundException(java.nio.file.ProviderNotFoundException) HashMap(java.util.HashMap) FileSystemAlreadyExistsException(java.nio.file.FileSystemAlreadyExistsException) Test(org.junit.Test)

Example 2 with ProviderNotFoundException

use of java.nio.file.ProviderNotFoundException in project j2objc by google.

the class ProviderNotFoundExceptionTest method test_constructor$String.

public void test_constructor$String() {
    String message = "message";
    ProviderNotFoundException exception = new ProviderNotFoundException(message);
    assertEquals(message, exception.getMessage());
    message = null;
    exception = new ProviderNotFoundException(message);
    assertEquals(message, exception.getMessage());
}
Also used : ProviderNotFoundException(java.nio.file.ProviderNotFoundException)

Example 3 with ProviderNotFoundException

use of java.nio.file.ProviderNotFoundException in project alien4cloud by alien4cloud.

the class ToscaArchiveParser method parseImports.

@ToscaContextual(requiresNew = true)
public ParsingResult<CsarDependenciesBean> parseImports(Path archiveFile) throws ParsingException {
    try (FileSystem csarFS = FileSystems.newFileSystem(archiveFile, null)) {
        if (Files.exists(csarFS.getPath(TOSCA_META_FILE_LOCATION))) {
            YamlSimpleParser<ToscaMeta> parser = new YamlSimpleParser<ToscaMeta>(toscaMetaMapping.getParser());
            ParsingResult<ToscaMeta> parsingResult = parser.parseFile(csarFS.getPath(TOSCA_META_FILE_LOCATION));
            CsarDependenciesBean csarDependenciesBean = initDependencyBeanFromToscaMeta(parsingResult.getResult());
            return parseFromToscaMeta(csarFS, parsingResult.getResult(), TOSCA_META_FILE_LOCATION, csarDependenciesBean, toscaImportParser);
        }
        return parseFromRootDefinitions(csarFS, toscaImportParser);
    } catch (IOException e) {
        log.error("Unable to read uploaded archive [" + archiveFile + "]", e);
        throw new ParsingException("Archive", new ParsingError(ErrorCode.FAILED_TO_READ_FILE, "Problem happened while accessing file", null, null, null, archiveFile.toString()));
    } catch (ProviderNotFoundException e) {
        log.warn("Failed to import archive", e);
        throw new ParsingException("Archive", new ParsingError(ErrorCode.ERRONEOUS_ARCHIVE_FILE, "File is not in good format, only zip file is supported ", null, e.getMessage(), null, null));
    }
}
Also used : ProviderNotFoundException(java.nio.file.ProviderNotFoundException) ToscaMeta(alien4cloud.tosca.model.ToscaMeta) FileSystem(java.nio.file.FileSystem) IOException(java.io.IOException) CsarDependenciesBean(org.alien4cloud.tosca.model.CsarDependenciesBean) ToscaContextual(alien4cloud.tosca.context.ToscaContextual)

Example 4 with ProviderNotFoundException

use of java.nio.file.ProviderNotFoundException in project beam by apache.

the class JavaUdfLoader method loadJar.

private FunctionDefinitions loadJar(String jarPath) throws IOException {
    if (functionCache.containsKey(jarPath)) {
        LOG.debug("Using cached function definitions from {}", jarPath);
        return functionCache.get(jarPath);
    }
    ClassLoader classLoader = createClassLoader(jarPath);
    Map<List<String>, ScalarFn> scalarFunctions = new HashMap<>();
    Map<List<String>, AggregateFn> aggregateFunctions = new HashMap<>();
    Iterator<UdfProvider> providers = getUdfProviders(classLoader);
    int providersCount = 0;
    while (providers.hasNext()) {
        providersCount++;
        UdfProvider provider = providers.next();
        provider.userDefinedScalarFunctions().forEach((functionName, implementation) -> {
            List<String> functionPath = ImmutableList.copyOf(functionName.split("\\."));
            if (scalarFunctions.containsKey(functionPath)) {
                throw new IllegalArgumentException(String.format("Found multiple definitions of scalar function %s in %s.", functionName, jarPath));
            }
            scalarFunctions.put(functionPath, implementation);
        });
        provider.userDefinedAggregateFunctions().forEach((functionName, implementation) -> {
            List<String> functionPath = ImmutableList.copyOf(functionName.split("\\."));
            if (aggregateFunctions.containsKey(functionPath)) {
                throw new IllegalArgumentException(String.format("Found multiple definitions of aggregate function %s in %s.", functionName, jarPath));
            }
            aggregateFunctions.put(functionPath, implementation);
        });
    }
    if (providersCount == 0) {
        throw new ProviderNotFoundException(String.format("No %s implementation found in %s. Create a class implementing %s and annotate it with @AutoService(%s.class).", UdfProvider.class.getSimpleName(), jarPath, UdfProvider.class.getSimpleName(), UdfProvider.class.getSimpleName()));
    }
    LOG.info("Loaded {} implementations of {} from {} with {} scalar function(s).", providersCount, UdfProvider.class.getSimpleName(), jarPath, scalarFunctions.size());
    FunctionDefinitions userFunctionDefinitions = FunctionDefinitions.newBuilder().setScalarFunctions(ImmutableMap.copyOf(scalarFunctions)).setAggregateFunctions(ImmutableMap.copyOf(aggregateFunctions)).build();
    functionCache.put(jarPath, userFunctionDefinitions);
    return userFunctionDefinitions;
}
Also used : ScalarFn(org.apache.beam.sdk.extensions.sql.udf.ScalarFn) HashMap(java.util.HashMap) UdfProvider(org.apache.beam.sdk.extensions.sql.udf.UdfProvider) ProviderNotFoundException(java.nio.file.ProviderNotFoundException) AggregateFn(org.apache.beam.sdk.extensions.sql.udf.AggregateFn) URLClassLoader(java.net.URLClassLoader) ArrayList(java.util.ArrayList) List(java.util.List) ImmutableList(org.apache.beam.vendor.guava.v26_0_jre.com.google.common.collect.ImmutableList)

Example 5 with ProviderNotFoundException

use of java.nio.file.ProviderNotFoundException in project j2objc by google.

the class FileSystemsTest method test_newFileSystem$Path$ClassLoader.

/* J2ObjC removed: PathClassLoader unsupported
    @Test
    public void test_newFileSystem$URI$Map$ClassLoader_customClassLoader() throws Exception {
        Map<String, String> stubEnv = new HashMap<>();
        // Verify that the Thread's classloader cannot load mypackage.MockFileSystem.
        try {
            Thread.currentThread().getContextClassLoader().loadClass("mypackage.MockFileSystem");
            fail();
        } catch (ClassNotFoundException expected) {}

        ClassLoader fileSystemsClassLoader = createClassLoaderForTestFileSystems();

        // The file system configured in filesystemstest.jar is for scheme "stubScheme://
        URI stubURI = new URI("stubScheme://sometext");
        FileSystem fs = FileSystems.newFileSystem(stubURI, stubEnv, fileSystemsClassLoader);
        assertEquals("mypackage.MockFileSystem", fs.getClass().getName());
        assertSame(stubURI, fs.getClass().getDeclaredMethod("getURI").invoke(fs));
        assertSame(stubEnv, fs.getClass().getDeclaredMethod("getEnv").invoke(fs));
    }
     */
@Test
public void test_newFileSystem$Path$ClassLoader() throws Exception {
    Path testPath = Paths.get("/");
    try {
        FileSystems.newFileSystem(testPath, Thread.currentThread().getContextClassLoader());
        fail();
    } catch (ProviderNotFoundException expected) {
    }
    try {
        FileSystems.newFileSystem(null, Thread.currentThread().getContextClassLoader());
        fail();
    } catch (NullPointerException expected) {
    }
    try {
        FileSystems.newFileSystem(testPath, null);
        fail();
    } catch (ProviderNotFoundException expected) {
    }
}
Also used : Path(java.nio.file.Path) ProviderNotFoundException(java.nio.file.ProviderNotFoundException) Test(org.junit.Test)

Aggregations

ProviderNotFoundException (java.nio.file.ProviderNotFoundException)5 Path (java.nio.file.Path)2 HashMap (java.util.HashMap)2 Test (org.junit.Test)2 ToscaContextual (alien4cloud.tosca.context.ToscaContextual)1 ToscaMeta (alien4cloud.tosca.model.ToscaMeta)1 IOException (java.io.IOException)1 URLClassLoader (java.net.URLClassLoader)1 FileSystem (java.nio.file.FileSystem)1 FileSystemAlreadyExistsException (java.nio.file.FileSystemAlreadyExistsException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 CsarDependenciesBean (org.alien4cloud.tosca.model.CsarDependenciesBean)1 AggregateFn (org.apache.beam.sdk.extensions.sql.udf.AggregateFn)1 ScalarFn (org.apache.beam.sdk.extensions.sql.udf.ScalarFn)1 UdfProvider (org.apache.beam.sdk.extensions.sql.udf.UdfProvider)1 ImmutableList (org.apache.beam.vendor.guava.v26_0_jre.com.google.common.collect.ImmutableList)1