當前位置: 首頁>>代碼示例>>Java>>正文


Java JsonUtils類代碼示例

本文整理匯總了Java中org.axway.grapes.commons.utils.JsonUtils的典型用法代碼示例。如果您正苦於以下問題:Java JsonUtils類的具體用法?Java JsonUtils怎麽用?Java JsonUtils使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


JsonUtils類屬於org.axway.grapes.commons.utils包,在下文中一共展示了JsonUtils類的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: saveNotification

import org.axway.grapes.commons.utils.JsonUtils; //導入依賴的package包/類
/**
 * Serialize a resend action to be able to re-send the notification later
 *
 * @param notification GrapesNotification
 * @param build AbstractBuild
 */
private void saveNotification(final GrapesNotification notification, final AbstractBuild<?, ?> build) {
    final ResendBuildAction resendAction = new ResendBuildAction(notification);

    // Check if the notification is valid before serializing it
    if(!isValid(resendAction)){
        GrapesPlugin.getLogger().log(Level.SEVERE, "[GRAPES] Malformed Grapes Notification: Grapes plugin is trying to serialize a notification provided by another plugin but failed to resolve the notification.");
        return;
    }

    try{
        final String serializedResend = JsonUtils.serialize(resendAction);
        final File reportFolder = new File(GrapesPlugin.getBuildReportFolder(build).toURI());
        FileUtils.serialize(reportFolder, serializedResend, getNotificationId(notification));
    }catch (Exception e){
        GrapesPlugin.getLogger().log(Level.SEVERE, "[GRAPES] Failed to serialized a resend action ", e);
    }
}
 
開發者ID:Axway,項目名稱:grapes-jenkins-plugin,代碼行數:24,代碼來源:NotificationHandler.java

示例2: checkResendBuildActionJsonSerialization

import org.axway.grapes.commons.utils.JsonUtils; //導入依賴的package包/類
@Test
public void checkResendBuildActionJsonSerialization(){
    final ResendBuildAction resendBuildAction = new ResendBuildAction(GrapesNotification.NotificationType.POST_MODULE, new FilePath(new File("test")), "moduleName", "moduleVersion");

    Exception execution = null;

    try{
        final String serializedAction = JsonUtils.serialize(resendBuildAction);
        final ObjectMapper mapper = new ObjectMapper();
        mapper.disable(MapperFeature.USE_GETTERS_AS_SETTERS);
        final ResendBuildAction newResendBuildAction = mapper.readValue(serializedAction,ResendBuildAction.class);

        assertEquals(resendBuildAction, newResendBuildAction);
    }catch (Exception e){
        execution = e;
    }

    assertNull(execution);

}
 
開發者ID:Axway,項目名稱:grapes-jenkins-plugin,代碼行數:21,代碼來源:ResendBuildActionTest.java

示例3: checkResendBuildActionJsonSerializationWhilePathIsNull

import org.axway.grapes.commons.utils.JsonUtils; //導入依賴的package包/類
@Test
public void checkResendBuildActionJsonSerializationWhilePathIsNull(){
    final ResendBuildAction resendBuildAction = new ResendBuildAction(GrapesNotification.NotificationType.POST_MODULE, null, "moduleName", "moduleVersion");

    Exception execution = null;

    try{
        final String serializedAction = JsonUtils.serialize(resendBuildAction);
        final ObjectMapper mapper = new ObjectMapper();
        mapper.disable(MapperFeature.USE_GETTERS_AS_SETTERS);
        final ResendBuildAction newResendBuildAction = mapper.readValue(serializedAction,ResendBuildAction.class);

        assertEquals(resendBuildAction, newResendBuildAction);
    }catch (Exception e){
        execution = e;
    }

    assertNull(execution);

}
 
開發者ID:Axway,項目名稱:grapes-jenkins-plugin,代碼行數:21,代碼來源:ResendBuildActionTest.java

示例4: aggregate

import org.axway.grapes.commons.utils.JsonUtils; //導入依賴的package包/類
/**
 * Checks all the available reports and aggregates the existing ones
 *
 * @throws IOException
 * @throws MojoExecutionException
 */
public void aggregate() throws IOException, MojoExecutionException {
    final Map<String, File> subModules = getSubModuleReports();

    for(Map.Entry<String,File> submoduleReports : subModules.entrySet()){
        final MavenProject parentProject = getParentProject(submoduleReports.getKey());

        if(parentProject != null){
            final Module subModule = JsonUtils.unserializeModule(FileUtils.read(submoduleReports.getValue()));
            final Boolean updated = updateParent(parentProject, subModule);

            // removes the children that are taken into accounts into parent reports
            if(updated){
                final File subModuleFile = new File(workingFolder, GrapesMavenPlugin.getSubModuleFileName(submoduleReports.getKey()));
                subModuleFile.delete();
            }
        }
    }
}
 
開發者ID:Axway,項目名稱:grapes-maven-plugin,代碼行數:25,代碼來源:ModuleAggregator.java

示例5: getModule

import org.axway.grapes.commons.utils.JsonUtils; //導入依賴的package包/類
/**
 * Un-serialize a Module from Json file
 *
 * @param moduleFile File
 * @return Module
 * @throws IOException
 * @throws InterruptedException
 */
public static Module getModule(final FilePath moduleFile) throws IOException, InterruptedException {
    if (moduleFile.exists()) {
        final String serializedModule= moduleFile.readToString();
        return JsonUtils.unserializeModule(serializedModule);
    }

    getLogger().severe("[GRAPES] Wrong module report path: " + moduleFile.toURI().getPath());
    throw new IOException("[GRAPES] Failed to get report.");
}
 
開發者ID:Axway,項目名稱:grapes-jenkins-plugin,代碼行數:18,代碼來源:GrapesPlugin.java

示例6: getBuildInfo

import org.axway.grapes.commons.utils.JsonUtils; //導入依賴的package包/類
/**
 * Un-serialize a BuildInfo from Json file
 *
 * @param buildInfoFile File
 * @return Map<String,String>
 * @throws IOException
 * @throws InterruptedException
 */
public static Map<String,String> getBuildInfo(final FilePath buildInfoFile) throws IOException, InterruptedException {
    if (buildInfoFile.exists()) {
        final String serializedBuildInfo= buildInfoFile.readToString();
        return JsonUtils.unserializeBuildInfo(serializedBuildInfo);
    }

    getLogger().severe("[GRAPES] Wrong buildInfo path: " + buildInfoFile.toURI().getPath());
    throw new IOException("[GRAPES] Failed to get build info.");
}
 
開發者ID:Axway,項目名稱:grapes-jenkins-plugin,代碼行數:18,代碼來源:GrapesPlugin.java

示例7: getModule

import org.axway.grapes.commons.utils.JsonUtils; //導入依賴的package包/類
/**
 * Return a module from Json file in a targeted folder
 *
 * @param folder File
 * @param moduleJsonFileName String
 * @return Module
 * @throws MojoExecutionException
 * @throws IOException
 */
public static Module getModule(final File folder, final String moduleJsonFileName) throws MojoExecutionException, IOException {
    final File moduleFile = new File(folder, moduleJsonFileName);

    if(moduleFile.exists()){
        final String serializedModule = FileUtils.read(moduleFile);
        return JsonUtils.unserializeModule(serializedModule);
    }

    return null;
}
 
開發者ID:Axway,項目名稱:grapes-maven-plugin,代碼行數:20,代碼來源:GrapesMavenPlugin.java

示例8: testSimpleProjectWithOneModuleOneArtifactAndOneLicense

import org.axway.grapes.commons.utils.JsonUtils; //導入依賴的package包/類
/**
 * @throws Exception
 */
public void testSimpleProjectWithOneModuleOneArtifactAndOneLicense() throws Exception {
    File pom = getTestFile( "src/test/resources/materials/simple-project/pom.xml" );
    assertNotNull( pom );
    assertTrue( pom.exists() );

    final GenerateMojo generateMojo = (GenerateMojo) lookupMojo( "generate", pom );
    final MavenProject simpleProject = (MavenProject) getVariableValueFromObject( generateMojo, "project" );

    /* Fake artifact resolution */
    final RepositorySystem repositorySystemMock = mock(RepositorySystem.class);
    final ArtifactResolutionResult result = mock(ArtifactResolutionResult.class);
    when(repositorySystemMock.resolve(any(ArtifactResolutionRequest.class))).thenReturn(result);
    when(result.isSuccess()).thenReturn(true);

    setVariableValueToObject(generateMojo, "repositorySystem", repositorySystemMock);
    /* End */

    // Runs Mojo on the project
    generateMojo.execute();

    // Get generated Grapes module
    final String serializedModule = FileUtils.read(new File(simpleProject.getBasedir(), "target/grapes/"+GrapesMavenPlugin.MODULE_JSON_FILE_NAME));
    final Module simpleProjectModule = JsonUtils.unserializeModule(serializedModule);

    // Checks
    assertEquals(simpleProject.getGroupId() + ":" + simpleProject.getArtifactId() , simpleProjectModule.getName());
    assertEquals(simpleProject.getVersion() , simpleProjectModule.getVersion());
    assertEquals(0 , simpleProjectModule.getSubmodules().size());
    assertEquals(2 , simpleProjectModule.getArtifacts().size());

    final Artifact grapesArtifact = simpleProjectModule.getArtifacts().iterator().next();
    assertEquals(simpleProject.getArtifact().getGroupId() , grapesArtifact.getGroupId());
    assertEquals(simpleProject.getArtifact().getArtifactId() , grapesArtifact.getArtifactId());
    assertEquals(simpleProject.getArtifact().getVersion() , grapesArtifact.getVersion());
    assertEquals(simpleProject.getLicenses().get(0).getName(), grapesArtifact.getLicenses().get(0));

}
 
開發者ID:Axway,項目名稱:grapes-maven-plugin,代碼行數:41,代碼來源:GenerateMojoTest.java

示例9: execute

import org.axway.grapes.commons.utils.JsonUtils; //導入依賴的package包/類
public void execute() throws MojoExecutionException {
	if (isExecuteSkipped()) {
		return;
	}
    try {
        final ModuleAggregator aggregator = new ModuleAggregator(reactorProjects);
        final ModuleBuilder moduleBuilder = new ModuleBuilder();
        final ArtifactResolver artifactResolver = new ArtifactResolver(repositorySystem, localRepository, getLog());
        final LicenseResolver licenseResolver = new LicenseResolver(repositorySystem, localRepository, getLog());

        getLog().info("Collecting dependency information of " + project.getName());
        final Module module = moduleBuilder.getModule(project, licenseResolver, artifactResolver);

        // Serialize the collected information
        final String serializedModule = JsonUtils.serialize(module);
        getLog().debug("Json module : " + serializedModule);

        // Write file
        final File grapesFolder = GrapesMavenPlugin.getGrapesPluginWorkingFolder(reactorProjects.get(0));
        getLog().info("Serializing the notification in " + grapesFolder.getPath());

        if(project.equals(reactorProjects.get(0))){
            FileUtils.serialize(grapesFolder, serializedModule, GrapesMavenPlugin.MODULE_JSON_FILE_NAME);
        }
        else{
            final String subModuleName = project.getBasedir().getName();
            FileUtils.serialize(grapesFolder, serializedModule, GrapesMavenPlugin.getSubModuleFileName(subModuleName));
        }

        getLog().info("Report consolidation...");
        aggregator.aggregate();

    } catch (Exception e) {

        if(failOnError){
            throw new MojoExecutionException("An error occurred during Grapes reporting." , e);
        }
        else{
            getLog().debug("An error occurred during Grapes reporting.", e);
            getLog().error("Failed to build Grapes report.");
        }
    }
}
 
開發者ID:Axway,項目名稱:grapes-maven-plugin,代碼行數:44,代碼來源:GenerateMojo.java


注:本文中的org.axway.grapes.commons.utils.JsonUtils類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。