@Test public void testExistingRootAndRelPath() throws Exception { CgenConfiguration config = new CgenConfiguration(false); config.setRootPath(Paths.get("/tmp/src/main/java").toAbsolutePath()); config.setRelPath(Paths.get("")); URL baseURL = Paths.get("/tmp/src/main/resources").toUri().toURL(); CgenSaverDelegate.resolveOutputDir(baseURL, config); assertEquals(Paths.get("/tmp/src/main/resources").toAbsolutePath(), config.getRootPath()); assertEquals(Paths.get("../java"), config.getRelPath()); }
static void resolveOutputDir(URL baseURL, CgenConfiguration cgenConfiguration) { if(baseURL == null) { return; } Path resourcePath; try { resourcePath = Paths.get(baseURL.toURI()); } catch (URISyntaxException e) { throw new CayenneRuntimeException("Unable to resolve output path", e); } if(Files.isRegularFile(resourcePath)) { resourcePath = resourcePath.getParent(); } Path oldRoot = cgenConfiguration.getRootPath(); if(oldRoot == null) { cgenConfiguration.setRootPath(resourcePath); } Path prevPath = cgenConfiguration.buildPath(); if(prevPath != null) { if(prevPath.isAbsolute()) { Path relPath = resourcePath.relativize(prevPath).normalize(); cgenConfiguration.setRelPath(relPath); } Path templatePath = Paths.get(cgenConfiguration.getTemplate()); if(templatePath.isAbsolute()) { cgenConfiguration.setTemplate(resourcePath.relativize(templatePath).normalize().toString()); } Path superTemplatePath = Paths.get(cgenConfiguration.getSuperTemplate()); if(superTemplatePath.isAbsolute()) { cgenConfiguration.setSuperTemplate(resourcePath.relativize(superTemplatePath).normalize().toString()); } } cgenConfiguration.setRootPath(resourcePath); }
CgenSaverDelegate extends BaseSaverDelegate { static void resolveOutputDir(URL baseURL, CgenConfiguration cgenConfiguration) { if(baseURL == null) { return; } Path resourcePath; try { resourcePath = Paths.get(baseURL.toURI()); } catch (URISyntaxException e) { throw new CayenneRuntimeException("Unable to resolve output path", e); } if(Files.isRegularFile(resourcePath)) { resourcePath = resourcePath.getParent(); } Path oldRoot = cgenConfiguration.getRootPath(); if(oldRoot == null) { cgenConfiguration.setRootPath(resourcePath); } Path prevPath = cgenConfiguration.buildPath(); if(prevPath != null) { if(prevPath.isAbsolute()) { Path relPath = resourcePath.relativize(prevPath).normalize(); cgenConfiguration.setRelPath(relPath); } Path templatePath = Paths.get(cgenConfiguration.getTemplate()); if(templatePath.isAbsolute()) { cgenConfiguration.setTemplate(resourcePath.relativize(templatePath).normalize().toString()); } Path superTemplatePath = Paths.get(cgenConfiguration.getSuperTemplate()); if(superTemplatePath.isAbsolute()) { cgenConfiguration.setSuperTemplate(resourcePath.relativize(superTemplatePath).normalize().toString()); } } cgenConfiguration.setRootPath(resourcePath); } }
CgenSaverDelegate extends BaseSaverDelegate { static void resolveOutputDir(URL baseURL, CgenConfiguration cgenConfiguration) { if(baseURL == null) { return; } Path resourcePath; try { resourcePath = Paths.get(baseURL.toURI()); } catch (URISyntaxException e) { throw new CayenneRuntimeException("Unable to resolve output path", e); } if(Files.isRegularFile(resourcePath)) { resourcePath = resourcePath.getParent(); } Path oldRoot = cgenConfiguration.getRootPath(); if(oldRoot == null) { cgenConfiguration.setRootPath(resourcePath); } Path prevPath = cgenConfiguration.buildPath(); if(prevPath != null) { if(prevPath.isAbsolute()) { Path relPath = resourcePath.relativize(prevPath).normalize(); cgenConfiguration.setRelPath(relPath); } Path templatePath = Paths.get(cgenConfiguration.getTemplate()); if(templatePath.isAbsolute()) { cgenConfiguration.setTemplate(resourcePath.relativize(templatePath).normalize().toString()); } Path superTemplatePath = Paths.get(cgenConfiguration.getSuperTemplate()); if(superTemplatePath.isAbsolute()) { cgenConfiguration.setSuperTemplate(resourcePath.relativize(superTemplatePath).normalize().toString()); } } cgenConfiguration.setRootPath(resourcePath); } CgenSaverDelegate(DataChannelMetaData metaData); }
CgenSaverDelegate extends BaseSaverDelegate { static void resolveOutputDir(URL baseURL, CgenConfiguration cgenConfiguration) { if(baseURL == null) { return; } Path resourcePath; try { resourcePath = Paths.get(baseURL.toURI()); } catch (URISyntaxException e) { throw new CayenneRuntimeException("Unable to resolve output path", e); } if(Files.isRegularFile(resourcePath)) { resourcePath = resourcePath.getParent(); } Path oldRoot = cgenConfiguration.getRootPath(); if(oldRoot == null) { cgenConfiguration.setRootPath(resourcePath); } Path prevPath = cgenConfiguration.buildPath(); if(prevPath != null) { if(prevPath.isAbsolute()) { Path relPath = resourcePath.relativize(prevPath).normalize(); cgenConfiguration.setRelPath(relPath); } Path templatePath = Paths.get(cgenConfiguration.getTemplate()); if(templatePath.isAbsolute()) { cgenConfiguration.setTemplate(resourcePath.relativize(templatePath).normalize().toString()); } Path superTemplatePath = Paths.get(cgenConfiguration.getSuperTemplate()); if(superTemplatePath.isAbsolute()) { cgenConfiguration.setSuperTemplate(resourcePath.relativize(superTemplatePath).normalize().toString()); } } cgenConfiguration.setRootPath(resourcePath); } CgenSaverDelegate(DataChannelMetaData metaData); @Override Void visitDataMap(DataMap dataMap); }
CgenSaverDelegate extends BaseSaverDelegate { static void resolveOutputDir(URL baseURL, CgenConfiguration cgenConfiguration) { if(baseURL == null) { return; } Path resourcePath; try { resourcePath = Paths.get(baseURL.toURI()); } catch (URISyntaxException e) { throw new CayenneRuntimeException("Unable to resolve output path", e); } if(Files.isRegularFile(resourcePath)) { resourcePath = resourcePath.getParent(); } Path oldRoot = cgenConfiguration.getRootPath(); if(oldRoot == null) { cgenConfiguration.setRootPath(resourcePath); } Path prevPath = cgenConfiguration.buildPath(); if(prevPath != null) { if(prevPath.isAbsolute()) { Path relPath = resourcePath.relativize(prevPath).normalize(); cgenConfiguration.setRelPath(relPath); } Path templatePath = Paths.get(cgenConfiguration.getTemplate()); if(templatePath.isAbsolute()) { cgenConfiguration.setTemplate(resourcePath.relativize(templatePath).normalize().toString()); } Path superTemplatePath = Paths.get(cgenConfiguration.getSuperTemplate()); if(superTemplatePath.isAbsolute()) { cgenConfiguration.setSuperTemplate(resourcePath.relativize(superTemplatePath).normalize().toString()); } } cgenConfiguration.setRootPath(resourcePath); } CgenSaverDelegate(DataChannelMetaData metaData); @Override Void visitDataMap(DataMap dataMap);  }