Skip to content

Commit

Permalink
remove duplicate methods
Browse files Browse the repository at this point in the history
Signed-off-by: Anatoli Kalbasin <qwnize@outlook.com>
  • Loading branch information
callbacksin committed Jan 14, 2025
1 parent f731709 commit 02a09d2
Show file tree
Hide file tree
Showing 20 changed files with 198 additions and 167 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@ stage ("stage-name") {
downloadDS dsn:"EXAMPLE.DATASET(MEMBER)", vol:"VOL001"
allocateDS dsn:"EXAMPLE.DATASET", alcUnit:"TRK", dsOrg:"PS", primary:1, secondary:1, recFm:"FB", failOnExist:"False"
writeFileToDS dsn:"EXAMPLE.DATASET", file:"workspaceFile"
writeFileToDS dsn:"EXAMPLE.DATASET(MEMBER)", file:"workspaceFile"
writeFileToDS dsn:"EXAMPLE.DATASET", file:"D:\\files\\localFile"
writeFileToDS dsn:"EXAMPLE.DATASET(MEMBER)", file:"D:\\files\\localFile"
writeToDS dsn:"EXAMPLE.DATASET", text:"Write this string to dataset"
writeFileToMember dsn:"EXAMPLE.DATASET", member:"MEMBER", file:"workspaceFile"
writeFileToMember dsn:"EXAMPLE.DATASET", member:"MEMBER", file:"D:\\files\\localFile"
writeToMember dsn:"EXAMPLE.DATASET", member:"MEMBER", text:"Write this string to member"
writeToDS dsn:"EXAMPLE.DATASET(MEMBER)", text:"Write this string to dataset member"
writeDirToDS dir: "app/src/main/cbl/", dsn: "EXAMPLE.DATASET"
writeDirToDS dir: "D:\\resources\\cbl", dsn: "EXAMPLE.DATASET", isLocalPath: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ import org.kohsuke.stapler.DataBoundSetter
import org.kohsuke.stapler.QueryParameter
import org.zowe.kotlinsdk.zowe.client.sdk.core.ZOSConnection
import org.zowe.zdevops.classic.core.AbstractBuildStep
import org.zowe.zdevops.logic.writeDirectoryToDataset
import org.zowe.zdevops.logic.writeDirectoryToPdsJenkins
import org.zowe.zdevops.utils.validateDatasetName
import org.zowe.zdevops.utils.validateFieldIsNotEmpty


/**
* A freestyle job Jenkins class for writing the contents of a directory to a PDS/E dataset.
* @see org.zowe.zdevops.declarative.jobs.WriteDirToDatasetDeclarative
* @see org.zowe.zdevops.declarative.files.dsn.WriteDirToDatasetDeclarative
*/
class WriteDirToDatasetStep
@DataBoundConstructor
Expand All @@ -58,7 +58,7 @@ constructor(
zosConnection: ZOSConnection
) {
val workspace = build.executor?.currentWorkspace ?: throw AbortException("'build.executor' was null")
writeDirectoryToDataset(dsn, dir, isLocalPath, workspace, listener, zosConnection)
writeDirectoryToPdsJenkins(dsn, dir, isLocalPath, workspace, listener, zosConnection)
}

@Extension
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
/*
* Copyright (c) 2023-2025 IBA Group.
*
* This program and the accompanying materials are made available under the terms of the
* Eclipse Public License v2.0 which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-v20.html
*
* SPDX-License-Identifier: EPL-2.0
*
* Copyright IBA Group 2023
* Contributors:
* IBA Group
* Zowe Community
*/

package org.zowe.zdevops.classic.files.dsn
Expand All @@ -24,8 +28,8 @@ import org.kohsuke.stapler.bind.JavaScriptMethod
import org.zowe.kotlinsdk.zowe.client.sdk.core.ZOSConnection
import org.zowe.zdevops.Messages
import org.zowe.zdevops.classic.core.AbstractBuildStep
import org.zowe.zdevops.logic.writeToDataset
import org.zowe.zdevops.utils.validateDatasetName
import org.zowe.zdevops.logic.writeTextToDatasetJenkins
import org.zowe.zdevops.utils.validateDsnOrDsnMemberName
import org.zowe.zdevops.utils.validateFieldIsNotEmpty
import java.io.File

Expand Down Expand Up @@ -93,7 +97,7 @@ constructor(
listener.logger.println(Messages.zdevops_declarative_writing_DS_from_file(dsn, file?.name, zosConnection.host, zosConnection.zosmfPort))
val fileContent = file?.readText()
if (fileContent != null) {
writeToDataset(listener, zosConnection, dsn, fileContent)
writeTextToDatasetJenkins(listener, zosConnection, dsn, fileContent)
}
}

Expand Down Expand Up @@ -155,7 +159,7 @@ constructor(
* @return FormValidation.ok() if the dataset name is valid, or an error message otherwise
*/
fun doCheckDsn(@QueryParameter dsn: String): FormValidation? {
return validateDatasetName(dsn)
return validateDsnOrDsnMemberName(dsn)
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
/*
* Copyright (c) 2023-2025 IBA Group.
*
* This program and the accompanying materials are made available under the terms of the
* Eclipse Public License v2.0 which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-v20.html
*
* SPDX-License-Identifier: EPL-2.0
*
* Copyright IBA Group 2023
* Contributors:
* IBA Group
* Zowe Community
*/

package org.zowe.zdevops.classic.files.dsn
Expand All @@ -24,7 +28,7 @@ import org.kohsuke.stapler.bind.JavaScriptMethod
import org.zowe.kotlinsdk.zowe.client.sdk.core.ZOSConnection
import org.zowe.zdevops.Messages
import org.zowe.zdevops.classic.core.AbstractBuildStep
import org.zowe.zdevops.logic.writeToMember
import org.zowe.zdevops.logic.writeTextToDatasetJenkins
import org.zowe.zdevops.utils.validateDatasetName
import org.zowe.zdevops.utils.validateFieldIsNotEmpty
import org.zowe.zdevops.utils.validateMemberName
Expand Down Expand Up @@ -94,9 +98,10 @@ constructor(
else -> throw AbortException(Messages.zdevops_classic_write_options_invalid())
}
listener.logger.println(Messages.zdevops_declarative_writing_DS_from_file(dsn, file?.name, zosConnection.host, zosConnection.zosmfPort))
listener.logger.println("[WARNING] - The method is deprecated. Please, consider switching to `Write File to Dataset` step.")
val fileContent = file?.readText()
if (fileContent != null) {
writeToMember(listener, zosConnection, dsn, member, fileContent)
writeTextToDatasetJenkins(listener, zosConnection, "$dsn($member)", fileContent)
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
/*
* Copyright (c) 2023-2025 IBA Group.
*
* This program and the accompanying materials are made available under the terms of the
* Eclipse Public License v2.0 which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-v20.html
*
* SPDX-License-Identifier: EPL-2.0
*
* Copyright IBA Group 2023
* Contributors:
* IBA Group
* Zowe Community
*/

package org.zowe.zdevops.classic.files.dsn
Expand All @@ -20,8 +24,8 @@ import org.kohsuke.stapler.QueryParameter
import org.zowe.kotlinsdk.zowe.client.sdk.core.ZOSConnection
import org.zowe.zdevops.Messages
import org.zowe.zdevops.classic.core.AbstractBuildStep
import org.zowe.zdevops.logic.writeToDataset
import org.zowe.zdevops.utils.validateDatasetName
import org.zowe.zdevops.logic.writeTextToDatasetJenkins
import org.zowe.zdevops.utils.validateDsnOrDsnMemberName
import org.zowe.zdevops.utils.validateFieldIsNotEmpty

/**
Expand Down Expand Up @@ -57,7 +61,7 @@ constructor(
zosConnection: ZOSConnection
) {
listener.logger.println(Messages.zdevops_declarative_writing_DS_from_input(dsn, zosConnection.host, zosConnection.zosmfPort))
writeToDataset(listener, zosConnection, dsn, text)
writeTextToDatasetJenkins(listener, zosConnection, dsn, text)
}

/**
Expand All @@ -72,7 +76,7 @@ constructor(
* @return FormValidation.ok() if the dataset name is valid, or an error message otherwise
*/
fun doCheckDsn(@QueryParameter dsn: String): FormValidation? {
return validateDatasetName(dsn)
return validateDsnOrDsnMemberName(dsn)
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
/*
* Copyright (c) 2023-2025 IBA Group.
*
* This program and the accompanying materials are made available under the terms of the
* Eclipse Public License v2.0 which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-v20.html
*
* SPDX-License-Identifier: EPL-2.0
*
* Copyright IBA Group 2023
* Contributors:
* IBA Group
* Zowe Community
*/

package org.zowe.zdevops.classic.files.dsn
Expand All @@ -20,7 +24,7 @@ import org.kohsuke.stapler.QueryParameter
import org.zowe.kotlinsdk.zowe.client.sdk.core.ZOSConnection
import org.zowe.zdevops.Messages
import org.zowe.zdevops.classic.core.AbstractBuildStep
import org.zowe.zdevops.logic.writeToMember
import org.zowe.zdevops.logic.writeTextToDatasetJenkins
import org.zowe.zdevops.utils.validateDatasetName
import org.zowe.zdevops.utils.validateFieldIsNotEmpty
import org.zowe.zdevops.utils.validateMemberName
Expand Down Expand Up @@ -60,7 +64,8 @@ constructor(
zosConnection: ZOSConnection
) {
listener.logger.println(Messages.zdevops_declarative_writing_DS_from_input(dsn, zosConnection.host, zosConnection.zosmfPort))
writeToMember(listener, zosConnection, dsn, member, text)
listener.logger.println("[WARNING] - The method is deprecated. Please, consider switching to `Write to Dataset` step.")
writeTextToDatasetJenkins(listener, zosConnection, "$dsn($member)", text)
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import org.kohsuke.stapler.DataBoundConstructor
import org.zowe.kotlinsdk.zowe.client.sdk.core.ZOSConnection
import org.zowe.zdevops.declarative.core.AbstractZosmfAction
import org.zowe.zdevops.declarative.jobs.zMessages
import org.zowe.zdevops.logic.writeDirectoryToDataset
import org.zowe.zdevops.logic.writeDirectoryToPdsJenkins

/**
* A declarative class for writing the contents of a directory to a PDS/E dataset.
Expand Down Expand Up @@ -67,7 +67,7 @@ class WriteDirToDatasetDeclarative
listener: TaskListener,
zosConnection: ZOSConnection
) {
writeDirectoryToDataset(dsn, dir, isLocalPath, workspace, listener, zosConnection)
writeDirectoryToPdsJenkins(dsn, dir, isLocalPath, workspace, listener, zosConnection)
}

@Symbol("writeDirToDS")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,31 @@
/*
* Copyright (c) 2022-2025 IBA Group.
*
* This program and the accompanying materials are made available under the terms of the
* Eclipse Public License v2.0 which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-v20.html
*
* SPDX-License-Identifier: EPL-2.0
*
* Copyright IBA Group 2022
* Contributors:
* IBA Group
* Zowe Community
*/

package org.zowe.zdevops.declarative.files.dsn

import org.zowe.kotlinsdk.zowe.client.sdk.core.ZOSConnection
import org.zowe.kotlinsdk.zowe.client.sdk.zosfiles.ZosDsn
import org.zowe.zdevops.declarative.core.AbstractZosmfAction
import hudson.*
import hudson.EnvVars
import hudson.Extension
import hudson.FilePath
import hudson.Launcher
import hudson.model.Run
import hudson.model.TaskListener
import org.jenkinsci.Symbol
import org.kohsuke.stapler.DataBoundConstructor
import org.zowe.kotlinsdk.zowe.client.sdk.core.ZOSConnection
import org.zowe.zdevops.declarative.core.AbstractZosmfAction
import org.zowe.zdevops.declarative.jobs.zMessages
import org.zowe.zdevops.logic.writeTextToDatasetJenkins
import java.io.File
import java.nio.file.Paths

Expand Down Expand Up @@ -47,18 +53,8 @@ class WriteFIleToMemberDeclarative @DataBoundConstructor constructor(private val
File("$workspacePath$file")
}

val targetDS = ZosDsn(zosConnection).getDatasetInfo(dsn)
val targetDSLRECL = targetDS.recordLength ?: throw AbortException(zMessages.zdevops_declarative_writing_DS_no_info(dsn))
val ineligibleStrings = textFile
.readLines()
.map { it.length }
.fold(0) { result, currStrLength -> if (currStrLength > targetDSLRECL) result + 1 else result }
if (ineligibleStrings > 0) {
throw AbortException(zMessages.zdevops_declarative_writing_DS_ineligible_strings(ineligibleStrings, dsn))
}
val textString = textFile.readText().replace("\r","")
ZosDsn(zosConnection).writeDsn(dsn, member, textString.toByteArray())
listener.logger.println(zMessages.zdevops_declarative_writing_DS_success(dsn))
listener.logger.println("[WARNING] - The method `writeFileToMember` is deprecated. Please, consider switching to `writeFileToDataset`.")
writeTextToDatasetJenkins(listener, zosConnection, "$dsn($member)", textFile.readText())
}


Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,31 @@
/*
* Copyright (c) 2022-2025 IBA Group.
*
* This program and the accompanying materials are made available under the terms of the
* Eclipse Public License v2.0 which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-v20.html
*
* SPDX-License-Identifier: EPL-2.0
*
* Copyright IBA Group 2022
* Contributors:
* IBA Group
* Zowe Community
*/

package org.zowe.zdevops.declarative.files.dsn

import org.zowe.kotlinsdk.zowe.client.sdk.core.ZOSConnection
import org.zowe.kotlinsdk.zowe.client.sdk.zosfiles.ZosDsn
import org.zowe.zdevops.declarative.core.AbstractZosmfAction
import hudson.*
import hudson.EnvVars
import hudson.Extension
import hudson.FilePath
import hudson.Launcher
import hudson.model.Run
import hudson.model.TaskListener
import org.jenkinsci.Symbol
import org.kohsuke.stapler.DataBoundConstructor
import org.zowe.kotlinsdk.zowe.client.sdk.core.ZOSConnection
import org.zowe.zdevops.declarative.core.AbstractZosmfAction
import org.zowe.zdevops.declarative.jobs.zMessages
import org.zowe.zdevops.logic.writeTextToDatasetJenkins
import java.io.File
import java.nio.file.Paths

Expand All @@ -46,23 +52,7 @@ class WriteFileToDatasetDeclarative @DataBoundConstructor constructor(private va
File("$workspacePath$file")
}

val targetDS = ZosDsn(zosConnection).getDatasetInfo(dsn)
if (targetDS.recordLength == null) {
throw AbortException(zMessages.zdevops_declarative_writing_DS_no_info(dsn))
}
var ineligibleStrings = 0
textFile.readLines().forEach {
if (it.length > targetDS.recordLength!!) {
ineligibleStrings++
}
}
if (ineligibleStrings > 0) {
throw AbortException(zMessages.zdevops_declarative_writing_DS_ineligible_strings(ineligibleStrings,dsn))
} else {
val textString = textFile.readText().replace("\r","")
ZosDsn(zosConnection).writeDsn(dsn, textString.toByteArray())
listener.logger.println(zMessages.zdevops_declarative_writing_DS_success(dsn))
}
writeTextToDatasetJenkins(listener, zosConnection, dsn, textFile.readText())
}


Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,31 @@
/*
* Copyright (c) 2022-2025 IBA Group.
*
* This program and the accompanying materials are made available under the terms of the
* Eclipse Public License v2.0 which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-v20.html
*
* SPDX-License-Identifier: EPL-2.0
*
* Copyright IBA Group 2022
* Contributors:
* IBA Group
* Zowe Community
*/

package org.zowe.zdevops.declarative.files.dsn

import hudson.*
import hudson.EnvVars
import hudson.Extension
import hudson.FilePath
import hudson.Launcher
import hudson.model.Run
import hudson.model.TaskListener
import org.jenkinsci.Symbol
import org.kohsuke.stapler.DataBoundConstructor
import org.zowe.kotlinsdk.zowe.client.sdk.core.ZOSConnection
import org.zowe.zdevops.declarative.core.AbstractZosmfAction
import org.zowe.zdevops.declarative.jobs.zMessages
import org.zowe.zdevops.logic.writeToDataset
import org.zowe.zdevops.logic.writeTextToDatasetJenkins

class WriteToDatasetDeclarative @DataBoundConstructor constructor(private val dsn: String,
private val text: String) :
Expand All @@ -34,7 +41,7 @@ class WriteToDatasetDeclarative @DataBoundConstructor constructor(private val ds
listener: TaskListener,
zosConnection: ZOSConnection
) {
writeToDataset(listener, zosConnection, dsn, text)
writeTextToDatasetJenkins(listener, zosConnection, dsn, text)
}


Expand Down
Loading

0 comments on commit 02a09d2

Please sign in to comment.