List of usage examples for org.apache.commons.lang3.mutable MutableBoolean MutableBoolean
public MutableBoolean(final Boolean value)
From source file:com.ibm.jaggr.core.impl.modulebuilder.javascript.JavaScriptModuleBuilder.java
@Override public ModuleBuild build(String mid, IResource resource, HttpServletRequest request, List<ICacheKeyGenerator> keyGens) throws Exception { final IAggregator aggr = (IAggregator) request.getAttribute(IAggregator.AGGREGATOR_REQATTRNAME); // Get the parameters from the request CompilationLevel level = getCompilationLevel(request); boolean createNewKeyGen = (keyGens == null); boolean isHasFiltering = RequestUtil.isHasFiltering(request); // If the source doesn't exist, throw an exception. if (!resource.exists()) { if (log.isLoggable(Level.WARNING)) { log.warning(MessageFormat.format(Messages.JavaScriptModuleBuilder_0, new Object[] { resource.getURI().toString() })); }/* w ww .j av a 2 s . co m*/ throw new NotFoundException(resource.getURI().toString()); } List<JSSourceFile> sources = this.getJSSource(mid, resource, request, keyGens); JSSource source = null; if (level == null) { // If optimization level is none, then we need to modify the source code // when expanding require lists and exporting module names because the // parsed AST produced by closure does not preserve whitespace and comments. StringBuffer code = new StringBuffer(); for (JSSourceFile sf : sources) { code.append(sf.getCode()); } source = new JSSource(code.toString(), mid); } boolean coerceUndefinedToFalse = aggr.getConfig().isCoerceUndefinedToFalse(); Features features = (Features) request.getAttribute(IHttpTransport.FEATUREMAP_REQATTRNAME); if (features == null || level == null || !RequestUtil.isHasFiltering(request)) { // If no features specified or we're only processing features to // get the dependency list for the cache key generator, then use // an empty feature set. features = Features.emptyFeatures; coerceUndefinedToFalse = false; } Set<String> discoveredHasConditionals = new LinkedHashSet<String>(); Set<String> hasFiltDiscoveredHasConditionals = new HashSet<String>(); String output = null; Compiler compiler = new Compiler(); CompilerOptions compiler_options = CompilerUtil.getDefaultOptions(); compiler_options.customPasses = HashMultimap.create(); if (isHasFiltering && (level != null || keyGens == null)) { // Run has filtering compiler pass if we are doing has filtering, or if this // is the first build for this module (keyGens == null) so that we can get // the dependent features for the module to include in the cache key generator. HasFilteringCompilerPass hfcp = new HasFilteringCompilerPass(features, keyGens == null ? hasFiltDiscoveredHasConditionals : null, coerceUndefinedToFalse); compiler_options.customPasses.put(CustomPassExecutionTime.BEFORE_CHECKS, hfcp); } boolean isReqExpLogging = RequestUtil.isRequireExpLogging(request); boolean isExpandRequires = RequestUtil.isExplodeRequires(request); List<ModuleDeps> expandedDepsList = null; MutableBoolean hasExpandableRequires = new MutableBoolean(false); if (isExpandRequires || createNewKeyGen) { expandedDepsList = new ArrayList<ModuleDeps>(); /* * Register the RequireExpansionCompilerPass if we're exploding * require lists to include nested dependencies */ RequireExpansionCompilerPass recp = new RequireExpansionCompilerPass(aggr, features, discoveredHasConditionals, expandedDepsList, hasExpandableRequires, isExpandRequires, (String) request.getAttribute(IHttpTransport.CONFIGVARNAME_REQATTRNAME), isReqExpLogging, source); compiler_options.customPasses.put(CustomPassExecutionTime.BEFORE_CHECKS, recp); // Call IRequestedModuleNames.getBaseLayerDeps() in case it throws an exception so that // we propagate it here instead of in layerBeginEndNotifier where we can't propagate // the exception. IRequestedModuleNames reqNames = (IRequestedModuleNames) request .getAttribute(IHttpTransport.REQUESTEDMODULENAMES_REQATTRNAME); if (reqNames != null) { reqNames.getRequireExpansionExcludes(); } } if (RequestUtil.isExportModuleName(request)) { compiler_options.customPasses.put(CustomPassExecutionTime.BEFORE_CHECKS, new ExportModuleNameCompilerPass(source)); } if (level != null && level != CompilationLevel.WHITESPACE_ONLY) { level.setOptionsForCompilationLevel(compiler_options); } else { // If CompilationLevel is WHITESPACE_ONLY, then don't call // setOptionsForCompilationLevel because it disables custom // compiler passes and we want them to run. // Allows annotations that are not standard. compiler_options.setWarningLevel(DiagnosticGroups.NON_STANDARD_JSDOC, CheckLevel.OFF); } // we do our own threading, so disable compiler threads. compiler.disableThreads(); // compile the module Result result = compiler.compile(externs, sources, compiler_options); if (result.success) { if (aggr.getOptions().isDevelopmentMode() && aggr.getOptions().isVerifyDeps()) { // Validate dependencies for this module by comparing the // discovered has conditionals against the dependent features // that were discovered when building the dependency graph List<String> dependentFeatures = aggr.getDependencies().getDependentFeatures(mid); if (dependentFeatures != null) { if (!new HashSet<String>(dependentFeatures).containsAll(hasFiltDiscoveredHasConditionals)) { throw new DependencyVerificationException(mid); } } } discoveredHasConditionals.addAll(hasFiltDiscoveredHasConditionals); if (keyGens != null) { // Determine if we need to update the cache key generator. Updating may be // necessary due to require list expansion as a result of different // dependency path traversals resulting from the specification of different // feature sets in the request. CacheKeyGenerator keyGen = (CacheKeyGenerator) keyGens.get(1); if (keyGen.featureKeyGen == null || keyGen.featureKeyGen.getFeatureSet() == null || !keyGen.featureKeyGen.getFeatureSet().containsAll(discoveredHasConditionals)) { discoveredHasConditionals.addAll(keyGen.featureKeyGen.getFeatureSet()); createNewKeyGen = true; } } if (level == null) { output = source.toString() + "\r\n"; //$NON-NLS-1$ } else { // Get the compiler output and set the data in the ModuleBuild output = compiler.toSource(); } } else { // Got a compiler error. Output a warning message to the browser console StringBuffer sb = new StringBuffer(MessageFormat.format(Messages.JavaScriptModuleBuilder_1, new Object[] { resource.getURI().toString() })); for (JSError error : result.errors) { sb.append("\r\n\t").append(error.description) //$NON-NLS-1$ .append(" (").append(error.lineNumber).append(")."); //$NON-NLS-1$ //$NON-NLS-2$ } if (aggr.getOptions().isDevelopmentMode() || aggr.getOptions().isDebugMode()) { // In development mode, return the error message // together with the uncompressed source. String errorMsg = StringUtil.escapeForJavaScript(sb.toString()); StringBuffer code = new StringBuffer(); for (JSSourceFile sf : sources) { code.append(sf.getCode()); } return new ModuleBuild(code.toString(), null, errorMsg); } else { throw new Exception(sb.toString()); } } return new ModuleBuild( expandedDepsList == null || expandedDepsList.size() == 0 ? output : new JavaScriptBuildRenderer(mid, output, expandedDepsList, isReqExpLogging), createNewKeyGen ? getCacheKeyGenerators(discoveredHasConditionals, hasExpandableRequires.getValue()) : keyGens, null); }
From source file:com.ibm.jaggr.core.impl.modulebuilder.javascript.RequireExpansionCompilerPassTest.java
@Test public void testHasPluginResolution() throws Exception { Features features = new Features(); Set<String> dependentFeatures = new TreeSet<String>(); features.put("feature1", true); features.put("feature2", true); List<ModuleDeps> expanded = new ArrayList<ModuleDeps>(); RequireExpansionCompilerPass pass = new RequireExpansionCompilerPass(mockAggregator, features, dependentFeatures, expanded, new MutableBoolean(false), true, null, false, null); String code, output;/*from w w w . j ava 2s .c o m*/ code = "require([\"has!feature1?has1\",\"has!feature2?has2\"]);"; output = runPass(pass, code); System.out.println(output); Assert.assertEquals("[feature1, feature2]", dependentFeatures.toString()); Assert.assertEquals("require([\"has!feature1?has1\",\"has!feature2?has2\",\"" + placeHolder0 + "\"]);", output); Assert.assertEquals(new LinkedHashSet<String>(Arrays.asList(new String[] { "dep1", "dep2" })), expanded.get(0).getModuleIds()); features.put("feature2", false); dependentFeatures.clear(); output = runPass(pass, code); Assert.assertEquals("[feature1, feature2]", dependentFeatures.toString()); Assert.assertEquals("require([\"has!feature1?has1\",\"has!feature2?has2\",\"" + placeHolder0 + "\"]);", output); Assert.assertEquals(new LinkedHashSet<String>(Arrays.asList(new String[] { "dep1" })), expanded.get(0).getModuleIds()); features.put("feature1", false); dependentFeatures.clear(); output = runPass(pass, code); Assert.assertEquals("[feature1, feature2]", dependentFeatures.toString()); Assert.assertEquals("require([\"has!feature1?has1\",\"has!feature2?has2\"]);", output); Assert.assertEquals(0, expanded.get(0).getModuleIds().size()); features.remove("feature2"); dependentFeatures.clear(); output = runPass(pass, code); Assert.assertEquals("[feature1, feature2]", dependentFeatures.toString()); Assert.assertEquals("require([\"has!feature1?has1\",\"has!feature2?has2\",\"" + placeHolder0 + "\"]);", output); Assert.assertEquals(new LinkedHashSet<String>(Arrays.asList(new String[] { "has!feature2?dep2" })), expanded.get(0).getModuleIds()); mockAggregator.getOptions().setOption(IOptions.DISABLE_HASPLUGINBRANCHING, true); output = runPass(pass, code); Assert.assertEquals("[feature1, feature2]", dependentFeatures.toString()); Assert.assertEquals("require([\"has!feature1?has1\",\"has!feature2?has2\"]);", output); Assert.assertEquals(0, expanded.get(0).getModuleIds().size()); mockAggregator.getOptions().setOption(IOptions.DISABLE_HASPLUGINBRANCHING, false); features.put("feature1", true); dependentFeatures.clear(); output = runPass(pass, code); Assert.assertEquals("[feature1, feature2]", dependentFeatures.toString()); Assert.assertEquals("require([\"has!feature1?has1\",\"has!feature2?has2\",\"" + placeHolder0 + "\"]);", output); Assert.assertEquals(new LinkedHashSet<String>(Arrays.asList(new String[] { "dep1", "has!feature2?dep2" })), expanded.get(0).getModuleIds()); features.remove("feature1"); dependentFeatures.clear(); output = runPass(pass, code); Assert.assertEquals("[feature1, feature2]", dependentFeatures.toString()); Assert.assertEquals("require([\"has!feature1?has1\",\"has!feature2?has2\",\"" + placeHolder0 + "\"]);", output); Assert.assertEquals( new LinkedHashSet<String>(Arrays.asList(new String[] { "has!feature1?dep1", "has!feature2?dep2" })), expanded.get(0).getModuleIds()); mockAggregator.getOptions().setOption(IOptions.DISABLE_HASPLUGINBRANCHING, true); output = runPass(pass, code); Assert.assertEquals("[feature1, feature2]", dependentFeatures.toString()); Assert.assertEquals("require([\"has!feature1?has1\",\"has!feature2?has2\"]);", output); Assert.assertEquals(0, expanded.get(0).getModuleIds().size()); }
From source file:com.ibm.jaggr.core.impl.modulebuilder.javascript.RequireExpansionCompilerPassTest.java
@Test public void testDependencyVerificationException() throws Exception { Features features = new Features(); Set<String> dependentFeatures = new TreeSet<String>(); features.put("feature1", true); features.put("feature2", true); List<ModuleDeps> expanded = new ArrayList<ModuleDeps>(); RequireExpansionCompilerPass pass = new RequireExpansionCompilerPass(mockAggregator, features, dependentFeatures, expanded, new MutableBoolean(false), true, null, false, null); mockAggregator.getOptions().setOption(IOptions.DEVELOPMENT_MODE, true); mockAggregator.getOptions().setOption(IOptions.VERIFY_DEPS, true); String code, output;//from w w w .j a v a2 s.co m moduleName = "x/y"; code = "define([\"x/y/z\", \"foo\", \"dep3\"], function(z, foo, dep3) {});"; try { output = runPass(pass, code); Assert.fail(); } catch (RuntimeDependencyVerificationException ex) { } // Ensure that duplicate dependencies in define statement doesn't // throw DependencyVerificationException code = "define([\"x/y/z\", \"foo\", \"x/y/z\"], function(z, foo) {});"; output = runPass(pass, code); System.out.println(output); }
From source file:com.ibm.jaggr.core.impl.modulebuilder.javascript.RequireExpansionCompilerPassTest.java
@Test public void testLogging() throws Exception { MutableBoolean hasExpandableRequires = new MutableBoolean(false); RequireExpansionCompilerPass pass = new RequireExpansionCompilerPass(mockAggregator, new Features(), null, new ArrayList<ModuleDeps>(), hasExpandableRequires, true, null, true, null); String code, output;/*from w ww .j a v a 2 s . c o m*/ code = "require([\"foo\"],function(){});"; output = runPass(pass, code); System.out.println(output); Assert.assertTrue("Expected pattern not found.", Pattern.compile("console\\.log\\(\\\"[^)\"]*Expanding requires list").matcher(output).find()); Assert.assertTrue("Output does not contain expected value.", output.contains( "foo (" + MessageFormat.format(com.ibm.jaggr.core.util.Messages.DependencyList_5, "test") + ")")); Assert.assertTrue("Output does not contain expected value.", output.contains( "bar (" + MessageFormat.format(com.ibm.jaggr.core.util.Messages.DependencyList_4, "foo") + ")")); Assert.assertTrue("Output does not contain expected value.", output.contains( "a/b (" + MessageFormat.format(com.ibm.jaggr.core.util.Messages.DependencyList_4, "bar") + ")")); Assert.assertTrue(hasExpandableRequires.getValue()); }
From source file:enumj.Enumerator.java
/** * Returns an infinite enumerator obtained by applying repeatedly the * provided unary operator.//from w ww . j av a 2 s. com * <p> * The resulted enumerator returns <code>seed</code>, * <code>f(seed)</code>, <code>f(f(seed))</code> ... * </p> * * @param <E> the type of enumerated elements * @param seed the initial element * @param f state-less {@link Function} instance to apply on the previous * element to obtain the next element * @return the iterated enumerator * @exception IllegalArgumentException <code>f</code> is null. */ public static <E> Enumerator<E> iterate(E seed, UnaryOperator<E> f) { Checks.ensureNotNull(f, Messages.NULL_ENUMERATOR_GENERATOR); final Mutable<E> result = new MutableObject(seed); final MutableBoolean first = new MutableBoolean(true); return of(() -> { if (first.booleanValue()) { first.setValue(false); } else { result.setValue(f.apply(result.getValue())); } return Optional.of(result.getValue()); }); }
From source file:forge.game.card.Card.java
@Override public final boolean canBeTargetedBy(final SpellAbility sa) { if (sa == null) { return true; }//from ww w.j a v a 2 s . c o m // CantTarget static abilities for (final Card ca : getGame().getCardsIn(ZoneType.listValueOf("Battlefield,Command"))) { final Iterable<StaticAbility> staticAbilities = ca.getStaticAbilities(); for (final StaticAbility stAb : staticAbilities) { if (stAb.applyAbility("CantTarget", this, sa)) { return false; } } } // keywords don't work outside battlefield if (!isInZone(ZoneType.Battlefield)) { return true; } if (hasProtectionFrom(sa.getHostCard())) { return false; } if (isPhasedOut()) { return false; } final Card source = sa.getHostCard(); final MutableBoolean result = new MutableBoolean(true); visitKeywords(currentState, new Visitor<String>() { @Override public void visit(String kw) { if (result.isFalse()) { return; } switch (kw) { case "Shroud": StringBuilder sb = new StringBuilder(); sb.append("Can target CardUID_").append(String.valueOf(getId())); sb.append(" with spells and abilities as though it didn't have shroud."); if (!sa.getActivatingPlayer().hasKeyword(sb.toString())) { result.setFalse(); } break; case "Hexproof": if (sa.getActivatingPlayer().getOpponents().contains(getController())) { if (!sa.getActivatingPlayer() .hasKeyword("Spells and abilities you control can target hexproof creatures")) { result.setFalse(); } } break; case "CARDNAME can't be the target of Aura spells.": if (source.isAura() && sa.isSpell()) { result.setFalse(); } break; case "CARDNAME can't be enchanted.": if (source.isAura()) { result.setFalse(); } break; case "CARDNAME can't be equipped.": if (source.isEquipment()) { result.setFalse(); } break; case "CARDNAME can't be the target of red spells or abilities from red sources.": if (source.isRed()) { result.setFalse(); } break; case "CARDNAME can't be the target of black spells.": if (source.isBlack() && sa.isSpell()) { result.setFalse(); } break; case "CARDNAME can't be the target of blue spells.": if (source.isBlue() && sa.isSpell()) { result.setFalse(); } break; case "CARDNAME can't be the target of spells.": if (sa.isSpell()) { result.setFalse(); } break; } } }); if (result.isFalse()) { return false; } if (sa.isSpell() && source.hasStartOfKeyword("SpellCantTarget")) { final int keywordPosition = source.getKeywordPosition("SpellCantTarget"); final String parse = source.getKeywords().get(keywordPosition); final String[] k = parse.split(":"); final String[] restrictions = k[1].split(","); if (isValid(restrictions, source.getController(), source)) { return false; } } return true; }
From source file:org.apache.asterix.app.translator.QueryTranslator.java
public void handleDatasetDropStatement(AqlMetadataProvider metadataProvider, Statement stmt, IHyracksClientConnection hcc) throws Exception { DropDatasetStatement stmtDelete = (DropDatasetStatement) stmt; String dataverseName = getActiveDataverse(stmtDelete.getDataverseName()); String datasetName = stmtDelete.getDatasetName().getValue(); MutableObject<ProgressState> progress = new MutableObject<>(ProgressState.NO_PROGRESS); MutableObject<MetadataTransactionContext> mdTxnCtx = new MutableObject<>( MetadataManager.INSTANCE.beginTransaction()); MutableBoolean bActiveTxn = new MutableBoolean(true); metadataProvider.setMetadataTxnContext(mdTxnCtx.getValue()); MetadataLockManager.INSTANCE.dropDatasetBegin(dataverseName, dataverseName + "." + datasetName); List<JobSpecification> jobsToExecute = new ArrayList<>(); try {//from w ww . j av a2s.c om Dataset ds = MetadataManager.INSTANCE.getDataset(mdTxnCtx.getValue(), dataverseName, datasetName); if (ds == null) { if (stmtDelete.getIfExists()) { MetadataManager.INSTANCE.commitTransaction(mdTxnCtx.getValue()); return; } else { throw new AlgebricksException("There is no dataset with this name " + datasetName + " in dataverse " + dataverseName + "."); } } doDropDataset(ds, datasetName, metadataProvider, mdTxnCtx, jobsToExecute, dataverseName, bActiveTxn, progress, hcc); MetadataManager.INSTANCE.commitTransaction(mdTxnCtx.getValue()); } catch (Exception e) { if (bActiveTxn.booleanValue()) { abort(e, e, mdTxnCtx.getValue()); } if (progress.getValue() == ProgressState.ADDED_PENDINGOP_RECORD_TO_METADATA) { // #. execute compensation operations // remove the all indexes in NC try { for (JobSpecification jobSpec : jobsToExecute) { JobUtils.runJob(hcc, jobSpec, true); } } catch (Exception e2) { // do no throw exception since still the metadata needs to be compensated. e.addSuppressed(e2); } // remove the record from the metadata. mdTxnCtx.setValue(MetadataManager.INSTANCE.beginTransaction()); metadataProvider.setMetadataTxnContext(mdTxnCtx.getValue()); try { MetadataManager.INSTANCE.dropDataset(metadataProvider.getMetadataTxnContext(), dataverseName, datasetName); MetadataManager.INSTANCE.commitTransaction(mdTxnCtx.getValue()); } catch (Exception e2) { e.addSuppressed(e2); abort(e, e2, mdTxnCtx.getValue()); throw new IllegalStateException("System is inconsistent state: pending dataset(" + dataverseName + "." + datasetName + ") couldn't be removed from the metadata", e); } } throw e; } finally { MetadataLockManager.INSTANCE.dropDatasetEnd(dataverseName, dataverseName + "." + datasetName); } }
From source file:org.apache.bookkeeper.bookie.BookieWriteToJournalTest.java
/** * test that Bookie calls correctly Journal.logAddEntry about "ackBeforeSync" parameter. *//*from ww w.j ava 2s . co m*/ @Test public void testJournalLogAddEntryCalledCorrectly() throws Exception { File journalDir = tempDir.newFolder(); Bookie.checkDirectoryStructure(Bookie.getCurrentDirectory(journalDir)); File ledgerDir = tempDir.newFolder(); Bookie.checkDirectoryStructure(Bookie.getCurrentDirectory(ledgerDir)); ServerConfiguration conf = TestBKConfiguration.newServerConfiguration(); conf.setJournalDirName(journalDir.getPath()).setLedgerDirNames(new String[] { ledgerDir.getPath() }) .setMetadataServiceUri(null); BookieSocketAddress bookieAddress = Bookie.getBookieAddress(conf); CountDownLatch journalJoinLatch = new CountDownLatch(1); Journal journal = mock(Journal.class); MutableBoolean effectiveAckBeforeSync = new MutableBoolean(false); doAnswer((Answer) (InvocationOnMock iom) -> { ByteBuf entry = iom.getArgument(0); long ledgerId = entry.getLong(entry.readerIndex() + 0); long entryId = entry.getLong(entry.readerIndex() + 8); boolean ackBeforeSync = iom.getArgument(1); WriteCallback callback = iom.getArgument(2); Object ctx = iom.getArgument(3); effectiveAckBeforeSync.setValue(ackBeforeSync); callback.writeComplete(BKException.Code.OK, ledgerId, entryId, bookieAddress, ctx); return null; }).when(journal).logAddEntry(any(ByteBuf.class), anyBoolean(), any(WriteCallback.class), any()); // bookie will continue to work as soon as the journal thread is alive doAnswer((Answer) (InvocationOnMock iom) -> { journalJoinLatch.await(); return null; }).when(journal).joinThread(); whenNew(Journal.class).withAnyArguments().thenReturn(journal); Bookie b = new Bookie(conf); b.start(); long ledgerId = 1; long entryId = 0; Object expectedCtx = "foo"; byte[] masterKey = new byte[64]; for (boolean ackBeforeSync : new boolean[] { true, false }) { CountDownLatch latch = new CountDownLatch(1); final ByteBuf data = buildEntry(ledgerId, entryId, -1); final long expectedEntryId = entryId; b.addEntry(data, ackBeforeSync, (int rc, long ledgerId1, long entryId1, BookieSocketAddress addr, Object ctx) -> { assertSame(expectedCtx, ctx); assertEquals(ledgerId, ledgerId1); assertEquals(expectedEntryId, entryId1); latch.countDown(); }, expectedCtx, masterKey); latch.await(30, TimeUnit.SECONDS); assertEquals(ackBeforeSync, effectiveAckBeforeSync.booleanValue()); entryId++; } // let bookie exit main thread journalJoinLatch.countDown(); b.shutdown(); }
From source file:org.apache.hyracks.maven.license.LicenseMojo.java
private void addDependencyToLicenseMap(MavenProject depProject, List<Pair<String, String>> depLicenses, String depLocation) {//from w ww . ja v a2s . c om final String depGav = toGav(depProject); getLog().debug("adding " + depGav + ", location: " + depLocation); final MutableBoolean usedMetric = new MutableBoolean(false); if (depLicenses.size() > 1) { Collections.sort(depLicenses, (o1, o2) -> { final int metric1 = getLicenseMetric(o1.getLeft()); final int metric2 = getLicenseMetric(o2.getLeft()); usedMetric.setValue(usedMetric.booleanValue() || metric1 != LicenseSpec.UNDEFINED_LICENSE_METRIC || metric2 != LicenseSpec.UNDEFINED_LICENSE_METRIC); return Integer.compare(metric1, metric2); }); if (usedMetric.booleanValue()) { getLog().info("Multiple licenses for " + depGav + ": " + depLicenses + "; taking lowest metric: " + depLicenses.get(0)); } else { getLog().warn("Multiple licenses for " + depGav + ": " + depLicenses + "; taking first listed: " + depLicenses.get(0)); } } else if (depLicenses.isEmpty()) { getLog().info("no license defined in model for " + depGav); depLicenses.add(new ImmutablePair<>("MISSING_LICENSE", null)); } Pair<String, String> key = depLicenses.get(0); String licenseUrl = key.getLeft(); final String displayName = key.getRight(); if (!urlToLicenseMap.containsKey(licenseUrl)) { // assuming we've not already mapped it, annotate the URL with artifact info, if not an actual URL try { getLog().debug("- URL: " + new URL(licenseUrl)); // life is good } catch (MalformedURLException e) { // we encounter this a lot. Log a warning, and use an annotated key final String fakeLicenseUrl = depGav.replaceAll(":", "--") + "_" + licenseUrl; getLog().info( "- URL for " + depGav + " is malformed: " + licenseUrl + "; using: " + fakeLicenseUrl); licenseUrl = fakeLicenseUrl; } } addProject(new Project(depProject, depLocation, depProject.getArtifact().getFile()), new LicenseSpec(licenseUrl, displayName), true); }
From source file:org.apache.mahout.cf.taste.impl.model.file.FileDataModelTest.java
@Test public void testRefresh() throws Exception { final MutableBoolean initialized = new MutableBoolean(false); Runnable initializer = new Runnable() { @Override//from www . ja va2 s. co m public void run() { try { model.getNumUsers(); initialized.setValue(true); } catch (TasteException te) { // oops } } }; new Thread(initializer).start(); Thread.sleep(1000L); // wait a second for thread to start and call getNumUsers() model.getNumUsers(); // should block assertTrue(initialized.booleanValue()); assertEquals(4, model.getNumUsers()); }