@Test public void loadDefaultCopyrightLines() throws IOException { String actualCopyrightFilePath = String.format("src/main/resources/com/google/api/codegen/%s", DEFAULT_COPYRIGHT_FILE); BufferedReader actualCopyrightReader = new BufferedReader(new FileReader(actualCopyrightFilePath)); String firstCopyrightLine = actualCopyrightReader.readLine(); List<String> defaultCopyrightLines = defaultHeaderUtil.loadCopyrightLines(); List<String> explicitCopyrightLines = explicitHeaderUtil.loadCopyrightLines(); assertThat(explicitCopyrightLines).isEqualTo(defaultCopyrightLines); assertThat(firstCopyrightLine).isEqualTo(defaultCopyrightLines.get(0)); assertThat(defaultHeaderUtil.getDiagCollector().getErrorCount()).isEqualTo(0); assertThat(explicitHeaderUtil.getDiagCollector().getErrorCount()).isEqualTo(0); }
public static LicenseHeaderUtil create( @Nullable ConfigProto configProto, @Nullable LanguageSettingsProto settings, @Nullable DiagCollector diagCollector) { Preconditions.checkNotNull(diagCollector); if (configProto != null) { Preconditions.checkNotNull( settings, "If configProto is non-null, then settings must also be non-null"); } LicenseHeaderProto licenseHeader = null; if (configProto != null) { licenseHeader = configProto .getLicenseHeader() .toBuilder() .mergeFrom(settings.getLicenseHeaderOverride()) .build(); } return new LicenseHeaderUtil(diagCollector, licenseHeader); }
public ImmutableList<String> loadLicenseLines() { String licenseFile; if (licenseHeader == null || Strings.isNullOrEmpty(licenseHeader.getLicenseFile())) { licenseFile = DEFAULT_LICENSE_FILE; } else { licenseFile = licenseHeader.getLicenseFile(); } return getResourceLines(licenseFile); }
try { LicenseHeaderUtil licenseHeaderUtil = LicenseHeaderUtil.create(configProto, settings, model.getDiagCollector()); copyrightLines = licenseHeaderUtil.loadCopyrightLines(); licenseLines = licenseHeaderUtil.loadLicenseLines(); } catch (Exception e) { model
@Test public void loadDefaultLicenseLines() throws IOException { String actualLicenseFilePath = String.format("src/main/resources/com/google/api/codegen/%s", DEFAULT_LICENSE_FILE); BufferedReader actualLicenseReader = new BufferedReader(new FileReader(actualLicenseFilePath)); String firstLicenseLine = actualLicenseReader.readLine(); List<String> defaultLicenseLines = defaultHeaderUtil.loadLicenseLines(); List<String> explicitLicenseLines = explicitHeaderUtil.loadLicenseLines(); assertThat(explicitLicenseLines).isEqualTo(defaultLicenseLines); assertThat(firstLicenseLine).isEqualTo(defaultLicenseLines.get(0)); assertThat(defaultHeaderUtil.getDiagCollector().getErrorCount()).isEqualTo(0); assertThat(explicitHeaderUtil.getDiagCollector().getErrorCount()).isEqualTo(0); }
@BeforeClass public static void startUp() { defaultHeaderUtil = LicenseHeaderUtil.create(null, null, new BoundedDiagCollector()); ConfigProto configProto = ConfigProto.newBuilder() .setLicenseHeader( LicenseHeaderProto.newBuilder() .setCopyrightFile(DEFAULT_COPYRIGHT_FILE) .setLicenseFile(DEFAULT_LICENSE_FILE)) .build(); explicitHeaderUtil = LicenseHeaderUtil.create( configProto, LanguageSettingsProto.getDefaultInstance(), new BoundedDiagCollector()); ConfigProto langOverrideConfigProto = configProto .toBuilder() .putLanguageSettings( LANGUAGE, LanguageSettingsProto.newBuilder() .setLicenseHeaderOverride( LicenseHeaderProto.newBuilder().setLicenseFile(IMAGINARY_FILE).build()) .build()) .build(); langOverrideHeaderUtil = LicenseHeaderUtil.create( langOverrideConfigProto, langOverrideConfigProto.getLanguageSettingsMap().get(LANGUAGE), new BoundedDiagCollector()); }
LicenseHeaderUtil.create( configProto, settings, model.getDiagReporter().getDiagCollector()); copyrightLines = licenseHeaderUtil.loadCopyrightLines(); licenseLines = licenseHeaderUtil.loadLicenseLines(); } catch (Exception e) { model
@Test public void testLanguageSettingsOverride() { try { langOverrideHeaderUtil.loadLicenseLines(); } catch (RuntimeException e) { // This is supposed to happen because IMAGINARY_FILE doesn't exist. assertThat(langOverrideHeaderUtil.getDiagCollector().getErrorCount()).isGreaterThan(0); return; } fail(); } }
public ImmutableList<String> loadCopyrightLines() { String filepath; if (licenseHeader == null || Strings.isNullOrEmpty(licenseHeader.getCopyrightFile())) { filepath = DEFAULT_COPYRIGHT_FILE; } else { filepath = licenseHeader.getCopyrightFile(); } return getResourceLines(filepath); }